Repository navigation
fix(url_decode): leave a stray % as written - #970
Conversation
url_decode passed its whole input to decodeURIComponent, so a single malformed escape (a "%" not followed by two hex digits, or an incomplete UTF-8 sequence) threw a RenderError and failed the render, discarding any valid escapes around it. It now decodes each run of well-formed escapes separately and leaves the rest as written, which is how Shopify's CGI.unescape treats a stray "%". "+" is still turned into a space before decoding, so %2B stays a literal plus. Fixes harttle#966 Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
|
I find one discrepency: Not sure for other cases, but you can check with Shopify/liquid. |
Each run of escapes was decoded with decodeURIComponent and kept as written if that threw, so one byte that isn't valid UTF-8 left its whole run undecoded: "caf%C3%A9%ff" rendered as written rather than "café�". Each run is now decoded as UTF-8 bytes, and a byte sequence that forms no character becomes U+FFFD, as the URL Standard's percent-decoding does. A leading byte order mark is kept, as decodeURIComponent keeps it. The docs page now states how malformed input renders. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Thanks for checking against Ruby. You're right about those two rows, and they led me to a worse case the first commit got wrong: one bad byte left its whole run of escapes undecoded, so The invalid-UTF-8 rows are the same question as base64 in #971; I've written up there why I think the render should continue. |
Each run of escapes is now decoded with decodeURIComponent rather than TextDecoder, so a run that isn't valid UTF-8 throws, as Shopify/Liquid does, instead of rendering U+FFFD. A "%" that isn't followed by two hex digits is still left as written. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Dropped |
url_decode(src/filters/url.ts:3) passes its whole input todecodeURIComponent, so a single%that isn't followed by two hex digits throws and fails the render.{{ v | url_decode }}:v100%100%100%%zz%zz%zz%E2%9C%93 done 100%✓ done 100%✓ done 100%a%2Bb 100%a+b 100%a+b 100%%E2%9C%ffcaf%C3%A9%ffcaf%C3%A9cafécafécaféa+b%20ca b ca b ca b cThis decodes each run of
%XXescapes withdecodeURIComponent, as Shopify'sCGI.unescapedecodes each run, so a stray%stays as written and a run that isn't valid UTF-8 still throws. For input that decodes today the output is unchanged, and+still becomes a space before decoding, so #939's%2Bhandling stays. The docs page for the filter now says how malformed input behaves.Two new tests in
test/integration/filters/url.spec.ts: a stray%beside valid escapes, which fails on master, and invalid UTF-8, which still throws.npm run build,npm test(1674 tests) andnpm run lintpass on Node 24.11.1.Fixes #966
Written with AI assistance (Claude Code); I have reviewed the change.