XML processing instruction loses its trailing ? since v11, so dom-serializer writes <?xml …>

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

维护者通常 1 天内回复

@ryanchou1994 已经在做这个了。

开始于 2026年11月6日。

  • #2563 来自 @ryanchou1994 —— 未关闭
  • #2566 来自 @MFA-G —— 已关闭,未合并

评估

难度
3/5
预计耗时
1-2 天
新手友好度
66/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
领域
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,通用步骤见我们的新手贡献指南。

从这里开始

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

fb55/htmlparser2 的其他 Issue

查看 fb55/htmlparser2 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

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