New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
HTML / unicode encoding issue with line item properties #1696
Comments
Just found another oddity. In /cart.js the greater than and less than symbols are converted to unicode: However in liquid, if I ever wanted to show the key of the property:
Nothing is printed. Internally it appears that whenever I access a line_item property key (or value), anything resembling an html tag is stripped before it's given to me / printed. And unless I'm mistaken this only appears to be with line_item properties. I can't recreate this behaviour elsewhere. |
@hedgehog90 im curious if you found a solution to the unicode problem - im having the same issue with strings containing single quotes, theyre being converted automatically to & # 3 9 ; and there seems to be no way of filtering this natively in Shopify. |
Only solution I think is to embed the json in a script tag of type "application/json" and process it client-side with Javascript. |
@twilson90 did you found any solution? |
Nope, see above ^ |
My products have color customization properties. The properties are stored in a product metafield as a json:
On the product page, the options are rendered as inputs with
name="properties[Branches & Birds Colour]"
After adding an item to cart with properties, on the cart page if I print
{{ cart.items.first.properties | json }}
I get this:[["Branches \u0026amp; Birds Colour","Leaf Green"],...]
The ampersand is converted into & then the & is unicode encoded... This appears to be the way all properties are encoded in the line item.
The equivalent of
{{ string | escape | json }}
.But if I print
{{ cart.items.first.product.metafields.namespace.custom_properties | json }}
I get:A problem then arises when I want to match the key in the cart to the metafield json property.
Practically, I want to show the color of each customization in the cart (using the hexadecimal value) by matching the property key with the metafield custom property definition, but the encoding messes this up.
I can't use url_decode on the line item property key, the unicode would need to be decoded first, and there appears to be no way in liquid to decode unicode.
So I'm stuck... unless I implement some hacky solution where I replace all instances of '\u0026amp;' with '\u0026', but this would only handle ampersand characters...
Is this a bug or am I missing something? Or is this just one more of Shopify's delightful quirks that I must learn to live with?
Either way, I'm welcome to any ideas on how to overcome this.
The text was updated successfully, but these errors were encountered: