Adding quotes around output markup with `| json` is not a safe formatting operation
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 234
- Forks
- 92
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 6
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the formatting change with Prettier 3.0.0 and @shopify/prettier-plugin-liquid 1.2.1 using the Liquid and HTML example in the report. Trace the formatter behavior for output markup containing the json filter, then verify that formatting preserves the unquoted form and does not add escaped quotes to the resulting dataset value.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100