Skip to content

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

Merged
harttle merged 1 commit into
harttle:masterfrom
sarathfrancis90:fix-url-decode-plus
Sep 6, 2026
Merged

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

Conversation

@sarathfrancis90

Copy link
Copy Markdown
Contributor

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.
@harttle
harttle merged commit 9af92f5 into harttle:master Sep 6, 2026
13 of 14 checks passed
@harttle

harttle commented Sep 6, 2026

Copy link
Copy Markdown
Owner

@all-contributors please add @sarathfrancis90 for code.

@allcontributors

Copy link
Copy Markdown
Contributor

@harttle

I've put up a pull request to add @sarathfrancis90! 🎉

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