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

Invalid url encoding handling #25

Merged
merged 2 commits into from
Apr 18, 2020
Merged

Invalid url encoding handling #25

merged 2 commits into from
Apr 18, 2020

Conversation

camdez
Copy link
Contributor

@camdez camdez commented Apr 11, 2020

Given the squashing of all exceptions in form-decode-str, the prior implementation of form-decode would return nil keys and/or values for parameters which failed to URL decode. With this change the parameters are silently dropped.

Including nil parameters creates problems for downstream middleware (e.g. ring.middleware.nested-params -- see ring-clojure/ring#243) which are not expecting them.

One can second guess the decision to catch all decoding exceptions (see #22) rather than allowing them to bubble up (and thus potentially allow the application to return an error status), but that decision being what it is, it seems most in the spirit of the library to drop the invalid parameters.

Note the two commits, with the first locking down the existing behavior so the second can clearly show the changes in behavior.

@weavejester
Copy link
Member

Thanks for the PR. Can you ensure that the commits adhere to the contributing guidelines.

@camdez
Copy link
Contributor Author

camdez commented Apr 11, 2020

@weavejester I think they generally do. Would you like for me to squash the commits and / or remove the additional tests? Or is there something else that I’m missing? Thanks.

@weavejester
Copy link
Member

Can you change the subject of the second commit to something like:

Exclude decoded params on invalid URL encoding

The rest of it is fine.

Given the squashing of all exceptions in form-decode-str, the prior
implementation of form-decode would return nil keys and/or values for
parameters which failed to URL decode.  With this change the
parameters are silently dropped.

Including nil parameters creates problems for downstream
middleware (e.g. ring.middleware.nested-params -- see
ring-clojure/ring#243) which are not expecting them, and has no basis
in the spec (https://url.spec.whatwg.org/#urlencoded-parsing).

One can second guess the decision to catch all decoding
exceptions (see #22) rather than allowing them to bubble up (and thus
potentially allow the application to return an error status), but that
decision being what it is, it seems most in the spirit of the library
to drop the invalid parameters.

For completeness, here are the (known) URL decoding failure cases:

- Illegal hex values in % escape pattern
- Incomplete % escape pattern
@camdez
Copy link
Contributor Author

camdez commented Apr 11, 2020

@weavejester Done!

@weavejester weavejester merged commit 58cccc5 into ring-clojure:master Apr 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants