XML processing instruction loses its trailing ? since v11, so dom-serializer writes <?xml …>
维护者通常 1 天内回复
评估
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 新手友好度
- 66/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 活跃
- 技术栈
- javascript, typescript
- 领域
- backend
调研方向
Start by reading the processing instruction handling described in #2382 and the parser and serializer behavior shown in the reproduction. Trace how htmlparser2 stores the instruction data and how dom-serializer writes it, then determine which side should preserve the trailing ?. Done means an XML parse → serialize round trip retains the ? before > without appending it twice.
由索引模型根据 Issue 内容生成。
描述
Since htmlparser2 11.0.0, the data of a processing instruction no longer ends with the ? of the ?> closer. dom-serializer writes a directive as <${data}>, so a parse → serialize round trip turns into <?xml …>, which is not well-formed XML.
Reproduction
import {parseDocument} from 'htmlparser2';
import render from 'dom-serializer';
const doc = parseDocument('<?xml version="1.0" encoding="UTF-8"?><a/>', {xmlMode: true});
console.log(JSON.stringify(doc.children[0].data));
console.log(render(doc, {xmlMode: true}));
| htmlparser2 | dom-serializer | data |
output |
|---|---|---|---|
| 10.1.0 | 2.0.0 | ?xml version="1.0" encoding="UTF-8"? |
<?xml version="1.0" encoding="UTF-8"?><a/> |
| 11.0.0 | 3.1.1 | ?xml version="1.0" encoding="UTF-8" |
<?xml version="1.0" encoding="UTF-8"><a/> |
| 12.0.0 | 3.1.1 | ?xml version="1.0" encoding="UTF-8" |
<?xml version="1.0" encoding="UTF-8"><a/> |
Node 26.3.0.
Cause
#2382 ("Wait for ?> in XML processing instructions") ends the instruction at this.index - 1, which excludes the ?. The release notes for 11.0.0 describe only the stricter termination, not a change of the data, so this looks unintended.
Expected
The round trip keeps . Either the data keeps the trailing ? as before 11.0.0, or dom-serializer appends ? when it writes a processing instruction. Which side should change is your call; the two must not both change.
- 主要语言
- TypeScript
- 星标
- 4.8k
- 派生
- 411
- 平均合并
- 14 小时 58 分钟
- 30 天内合并 PR
- 13
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
fb55/htmlparser2 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 78/100
fb55/htmlparser2#2579 ·
维护者通常 1 天内回复
-
难度 3/5 1-2 天 新手友好度 55/100
fb55/htmlparser2#2468 ·
维护者通常 1 天内回复
-
Option to disable implicit HTML changes可能已有人在做 @Gravirei 于 141 天前认领。 未关闭good-first-issue
难度 5/5 一周以上 新手友好度 35/100
fb55/htmlparser2#2428 · 1 条评论 ·
维护者通常 1 天内回复
相似的 Issue
-
bug good first issue needs-review
难度 1/5 1-3 小时 新手友好度 83/100
维护者通常 1 天内回复
-
documentation public
难度 1/5 1-3 小时 新手友好度 68/100
midnightntwrk/umbradb#65 ·
维护者通常 2 天内回复
-
area/channels kind/bug priority/medium
难度 2/5 1-3 小时 新手友好度 78/100
nanocoai/nanoclaw#4501 · 1 条评论 ·
维护者通常 1 天内回复
-
needs verification
难度 2/5 1-3 小时 新手友好度 74/100
维护者通常 13 天内回复
-
微软日程推送邮箱未关闭
难度 1/5 1 小时以内 新手友好度 68/100