Adding quotes around output markup with `| json` is not a safe formatting operation

未关闭
#377 2 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
typescript
领域
tooling

调研方向

使用报告中的 Liquid 和 HTML 示例,通过 Prettier 3.0.0 和 @shopify/prettier-plugin-liquid 1.2.1 重现格式变化。跟踪格式化程序对包含 json 过滤器的输出标记的行为,然后验证格式化会保留不带引号的形式,并且不会向生成的数据集值添加转义引号。

由索引模型根据 Issue 内容生成。

描述

area:prettier-plugin Bug Severity: 4

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 "&quot;someValue&quot;")

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
主要语言
TypeScript
星标
245
派生
108
平均合并
2 天 8 小时
30 天内合并 PR
24

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

Shopify/theme-tools 的其他 Issue

查看 Shopify/theme-tools 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。