A processing instruction with no target passes validation, then the builder prints invalid XML

未关闭 适合新手
#927 2 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 4 天内回复

@bardrop 已经在做这个了。

开始于 2026年11月17日。

  • #928 来自 @bardrop —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
78/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃

调研方向

从 XMLValidator 中处理处理指令的验证路径开始,然后将其对 <?x?> 和 <? ?> 的处理与 issue 中描述的 XML PI 语法进行比较。使用提供的 Node.js 示例检查 parser 和 builder 的行为。验证拒绝无效 target 的情况,或 parsing 跳过这些情况,从而使 builder 不会生成无效 XML,即为完成。

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

描述

  • Are you running the latest version?
  • Have you included sample input, output, error, and expected output?
  • Have you checked if you are using correct configuration?
  • Did you try online tool?
  • Have you checked the docs for helpful APIs and examples?
Description

Hello,

While fuzzing [email protected] (the latest version) with Termo, a fuzzer I'm developing, I found that XMLValidator accepts a processing instruction with no target name (<?>x?>). XMLParser then returns a node with an empty tag name, and XMLBuilder turns it into <></>, which is not XML:

// [email protected], Node.js v26.13.0
const { XMLValidator, XMLParser, XMLBuilder } = require('fast-xml-parser');
const options = { ignoreAttributes: false, preserveOrder: true };
const input = '<?>x?><r/>';
console.log(XMLValidator.validate(input));            // true
const parsed = new XMLParser(options).parse(input);
console.log(JSON.stringify(parsed));                  // [{"":[{"#text":""}]},{"r":[]}]
const built = new XMLBuilder(options).build(parsed);
console.log(built);                                   // <></><r></r>
console.log(XMLValidator.validate(built) === true);   // false

Without a target (<?>) validation already fails as it should. With a body (<?>x?>) it passes. The XML spec requires a name right after <? (PI ::= '<?' PITarget (S ...)? '?>').

<? ?><r/> is similar: it validates, and parses into a node named "?", which the builder prints as <??>.

Expected: the validator rejects a processing instruction with no target (or else the parser skips it), so the builder never prints an element with an empty name.

Happy to test a fix against these inputs if it helps.

If you'd like me to keep fuzzing fast-xml-parser (other parts of the API, or re-checking after a fix), feel free to reach out. I'd be glad to keep working on it with you.

Thanks!

主要语言
JavaScript
星标
3.1k
派生
410
平均合并
4 天 15 小时
30 天内合并 PR
8

环境准备

从这里开始

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

NaturalIntelligence/fast-xml-parser 的其他 Issue

查看 NaturalIntelligence/fast-xml-parser 的全部 Issue

相似的 Issue

更多 JavaScript Issue

把新 issue 发到你的邮箱

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