Short description of issue
search.terms returns HTML-encoded entities, breaking url_encode
Reproduction steps
Search for a term containing &, e.g. Hand & Feet
Use {{ search.terms | url_encode }} in a Liquid template
The output is Hand+%26amp%3B+Feet instead of Hand+%26+Feet
Additional info
search.terms returns the value already HTML-encoded (e.g. Hand & Feet instead of Hand & Feet). Calling | url_encode on top of that double-encodes the string and produces an invalid URL.
What type of topic is this
Bug report
Hi @Ilan_Zerdoun!
Thanks for flagging this with reproduction steps. We’re looking into the double-encoding you’re seeing with search.terms.
In the meantime, you can strip the extra encoding by chaining replace filters after url_encode:
{{ search.terms
| url_encode
| replace: '%26amp%3B', '%26'
| replace: '%26lt%3B', '%3C'
| replace: '%26gt%3B', '%3E'
| replace: '%26quot%3B', '%22'
| replace: '%26%2339%3B','%27'
}}
That covers the common entities (&, <, >, ", ').
I’ll post here as soon as we have an update to share.