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

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! 🎉

github-actions Bot pushed a commit that referenced this pull request Oct 1, 2026
# [10.30.0](v10.29.0...v10.30.0) (2026-10-01)

### Bug Fixes

* **base64_encode:** encode large input in browser builds ([#969](#969)) ([8aace78](8aace78)), closes [#967](#967)
* **date:** compute %C and %y from the numeric year ([#961](#961)) ([e68514f](e68514f))
* **date:** compute %U and %W week numbers like strftime ([#958](#958)) ([0587ca8](0587ca8))
* trim custom characters by Unicode code point ([#955](#955)) ([3fe244f](3fe244f))
* **truncatewords:** ignore leading whitespace when counting words ([#954](#954)) ([65e200e](65e200e))
* **url_decode:** keep %2B as a literal plus when decoding ([#939](#939)) ([9af92f5](9af92f5))

### Features

* await promises returned by Drop.valueOf() ([#948](#948)) ([#953](#953)) ([#959](#959)) ([7dfa76b](7dfa76b))
@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown

🎉 This PR is included in version 10.30.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants