Encode the id as a URL path segment, not a form value - #477
Merged
Conversation
`Base.element_path` and `CustomMethods#custom_method_element_url`
escaped `id` with `URI.encode_www_form_component`, an
`application/x-www-form-urlencoded` encoder. A space became `+`, so
`Person.find("ann mary")` requested `/people/ann+mary.json` and a
backend reading the path as a path saw the id as `ann+mary`. The
custom-method path had the same corruption.
Escape with `ERB::Util.url_encode` at both sites, matching the prefix
half. These were the only places in `lib/` where a runtime value was
form-encoded into a path.
Breaking: an id containing a space now goes on the wire as `%20`
rather than `+`, and a literal `+` as `%2B`. Nothing raises; the
request is simply made to a different URL. Backends that form-decode
the path are unaffected. Applications that compensated for the old
encoding must remove the workaround.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Base.element_pathandCustomMethods#custom_method_element_urlescaped
idwithURI.encode_www_form_component, anapplication/x-www-form-urlencodedencoder. A space became+, soPerson.find("ann mary")requested/people/ann+mary.jsonand abackend reading the path as a path saw the id as
ann+mary. Thecustom-method path had the same corruption.
Escape with
ERB::Util.url_encodeat both sites, matching the prefixhalf. These were the only places in
lib/where a runtime value wasform-encoded into a path.
Breaking: an id containing a space now goes on the wire as
%20rather than
+, and a literal+as%2B. Nothing raises; therequest is simply made to a different URL. Backends that form-decode
the path are unaffected. Applications that compensated for the old
encoding must remove the workaround.