prettier-plugin-liquid
prettier-plugin-liquid copied to clipboard
Adding quotes around output markup with `| json` is not a safe formatting operation
Describe the bug
Formatting the document causes quotation marks to be added around output markup that contains | json
, which is not a safe formatting operation if the value being piped to the json
filter is a string.
Unformatted source No quotes around the tag:
<div
data-something={{ someStringVar | json }}
></div>
Expected output (no change)
<div
data-something={{ someStringVar | json }}
></div>
Actual output Adds quotes around tag:
<div
data-something='{{ someStringVar | json }}'
></div>
Which gets evaluated as:
<div
data-something=""someValue""
></div>
(Or maybe that's just the way Chrome renders it on the 'Elements' tab. When I copy the outerHTML to a clipboard it looks like ""someValue""
)
And then the element's dataset
gets changed from:
{
something: 'someValue'
}
to:
{
something: '\"someValue\"'
}
Debugging information
- Ubuntu 20.04
- Prettier version 3.0.0
- @shopify/prettier-plugin-liquid version 1.2.1
Oof. Until this gets fixed, you should be able to use {% # prettier-ignore-attributes %}
for this.
I'm not entirely sure what our stance wants to be on this.
Because a variable could contain quotes in it, it would mean that we should never quote swap. If I turn that off, I'll get issues reporting that we don't quote swap :P and don't maintain a consistent style.