fix(url_decode): keep %2B as a literal plus when decoding - #939
Open
sarathfrancis90 wants to merge 1 commit into
Open
fix(url_decode): keep %2B as a literal plus when decoding#939sarathfrancis90 wants to merge 1 commit into
sarathfrancis90 wants to merge 1 commit into
Conversation
url_decode decoded the percent-encoding first and only then replaced "+" with a space, so a "%2B" became "+" and was immediately turned into a space. Any literal "+" was therefore lost when round-tripped through url_encode. I now replace "+" with a space before decodeURIComponent, which lines up with Ruby's CGI.unescape used by Shopify.
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.
I noticed that
url_decodeloses a literal+:{{ "1%2B1" | url_decode }}gives1 1instead of1+1, and anything with a+no longer survives aurl_encode | url_decoderound-trip (a+b ccomes back asa b c).The cause is ordering: it ran
decodeURIComponentfirst and only then replaced every+with a space, so a%2Bdecoded to+and was immediately turned into a space. I moved the+-to-space replacement ahead ofdecodeURIComponent, so encoded pluses survive. This matches Ruby'sCGI.unescapethat Shopify uses.Tested with two new cases in
test/integration/filters/url.spec.ts(the%2Bdecode and the round-trip), plus the full suite and lint.