Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

req.path docs don't specify if it's the encoded or decoded path #1281

Closed
benmccann opened this issue Aug 11, 2021 · 6 comments
Closed

req.path docs don't specify if it's the encoded or decoded path #1281

benmccann opened this issue Aug 11, 2021 · 6 comments
Labels

Comments

@benmccann
Copy link

https://expressjs.com/en/api.html#req.path

@dougwilson
Copy link
Contributor

I will have to take a look to verify, but it shoupd be whatever the client sent, as there is no encoding or decoding being done on it as far as I know.

@dougwilson
Copy link
Contributor

Yep, just double-checked and there is no normalization being done, which is the default expectation. Nothing is specified there as Express doesn't do anything to it (encoding or decoding).

@benmccann
Copy link
Author

I just tested and came to the same conclusion. I still think this would be good to document.

According to https://masteringjs.io/tutorials/express/req Express does parse the query string parameters, but does not parse the body

The fact that some things are parsed and others are not would be impossible to figure out from the docs today

@dougwilson
Copy link
Contributor

Unfortunately we don't control that website. The default expectation is that things are not altered from what they were sent as unless specified otherwise.

@benmccann
Copy link
Author

Should we at least update the docs for https://expressjs.com/en/api.html#req.query then? Because my understanding from the other website is that the query is parsed, but the Express deviates from the "default" expectation without documenting it (unless you're saying the other website is incorrect. It would be best if I could read the Express docs to figure out what to expect rather than relying on unstated assumptions and third-party websites)

@dougwilson
Copy link
Contributor

To be clear: req.path does parse the req.url value and output the path part. Parsing the URL is not the same as decoding sequences that were encoding using URL percent-encoding, though. Items are encoding with URL percent-encoding such that they do no interfere with the parsing of a URL. Automatic decoding of URL percent-encoded entries in a URL would cause issues such as %2e becoming a . and %2f becoming a / causing a very different-looking path than one would expect.

Should we at least update the docs for https://expressjs.com/en/api.html#req.query then? Because my understanding from the other website is that the query is parsed, but the Express deviates from the "default" expectation without documenting it (unless you're saying the other website is incorrect. It would be best if I could read the Express docs to figure out what to expect rather than relying on unstated assumptions and third-party websites)

I took a look at req.query and it is already documented.

This property is an object containing a property for each query string parameter in the route. When query parser is set to disabled, it is an empty object {}, otherwise it is the result of the configured query parser.

The value of req.query depends on which parser you have configured and how it operates, so documenting the specific results of just one of the parsers under req.query would be confusing. You should look at the documentation for your configured query parser to understand what it's output would result in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants