Skip to content

fix(url_decode): keep %2B as a literal plus when decoding - #939

Open
sarathfrancis90 wants to merge 1 commit into
harttle:masterfrom
sarathfrancis90:fix-url-decode-plus
Open

fix(url_decode): keep %2B as a literal plus when decoding#939
sarathfrancis90 wants to merge 1 commit into
harttle:masterfrom
sarathfrancis90:fix-url-decode-plus

Conversation

@sarathfrancis90

Copy link
Copy Markdown

I noticed that url_decode loses a literal +: {{ "1%2B1" | url_decode }} gives 1 1 instead of 1+1, and anything with a + no longer survives a url_encode | url_decode round-trip (a+b c comes back as a b c).

The cause is ordering: it ran decodeURIComponent first and only then replaced every + with a space, so a %2B decoded to + and was immediately turned into a space. I moved the +-to-space replacement ahead of decodeURIComponent, so encoded pluses survive. This matches Ruby's CGI.unescape that Shopify uses.

Tested with two new cases in test/integration/filters/url.spec.ts (the %2B decode and the round-trip), plus the full suite and lint.

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.
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.

1 participant