XMLValidator accepts raw < and & in attribute values

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

维护者通常 3 天内回复

@jeromeyyy 已经在做这个了。

开始于 2026年11月4日。

  • #913 来自 @jeromeyyy —— 未关闭

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
72/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
javascript
领域
data

调研方向

从验证器的 validateAttributeString 函数开始。issue 中说,该函数接收属性令牌扫描器传来的带引号的值,但没有检查其中是否含有原始的 '<' 或格式错误的 '&' 引用。将 issue 中的三个输入分别通过 XMLValidator.validate 和 parse(xml, true) 运行,以确认当前行为。完成标准是:前两个输入未通过验证,&amp; 对照用例仍然通过,且现有测试全部保持通过。

由索引模型根据 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 the online tool?
  • Have you checked the docs for helpful APIs and examples?
Description

On 5.11.2 (current master at cf66a9658004553bc740616e6c7a4912e7e9aab6), XMLValidator accepts raw ampersands and less-than signs inside quoted attribute values. XML 1.0's AttValue grammar excludes both literal characters there; an ampersand must begin a reference. This concerns attribute values, whereas #214 reported a stray ampersand in element text.

Input
<a x="&"/>
<a x="<"/>
<a x="&amp;"/>

The last input is a valid control.

Code
const { XMLParser, XMLValidator } = require('fast-xml-parser');

for (const xml of ['<a x="&"/>', '<a x="<"/>', '<a x="&amp;"/>']) {
  console.log(xml, XMLValidator.validate(xml));
}
console.log(new XMLParser({ ignoreAttributes: false }).parse('<a x="&"/>', true));
Output

XMLValidator.validate returns true for all three inputs. Parsing the raw-ampersand input with validation enabled returns { a: { '@_x': '&' } }. The official online validator also reports "Valid XML" for both malformed inputs.

Expected data

The first two inputs should return a validation error, and parse(xml, true) should reject them. The escaped control should remain valid. The attribute token scanner extracts the quoted value, but validateAttributeString does not check that value for raw '<' or malformed '&' references.

Would you like to work on this issue?

  • Yes
  • No
主要语言
JavaScript
星标
3.1k
派生
404
平均合并
2 天 1 小时
30 天内合并 PR
5

环境准备

从这里开始

  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 摘要。