Incorrect parsing of `<`angle brackets `>` as text characters
维护者通常 4 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 52/100
- Issue 类型
- 缺陷
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- javascript
- 领域
- tooling
调研方向
首先使用 preserveOrder 通过 XMLParser.parse 重现两个示例,然后检查这些输入所涉及的 parser 入口点以及 token/name 处理。使用 XMLBuilder.build 验证结果。完成的标准是:无效的尖括号序列仍保留为文本,并且两种情况下都保留有效的 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
I encountered a case where a text content like <...> inside a tag is incorrectly handled by the parser. The parser tries to interpret this as a tag name and breaks the tree structure. This is also applicable to the symbol \U+2026 Horizontal Ellipsis
What does <...> mean?
In text, <...> usually means something has been intentionally left out. It’s a placeholder that implies omitted words, omitted text that isn’t being shown, quoted, or repeated
However, the . symbol can indeed be used in the XML tag name, but only if it is not the starting character (NameStartChar in spec). And the ellipsis symbol seems to be invalid for NameChar. Please look at the Names and Tokens section here https://www.w3.org/TR/xml/#sec-common-syn
Also, while writing this issue, I tried using only the angle bracket characters individually and saw strange behavior. I've described this below as a second case.
I assume that the correct parser behavior if the angle brackets don't form a valid tag name according to XML specification would be to leave the angle bracket characters in the #text element or escape them in entities.
Input
Code
const xmlParser = new XMLParser({
preserveOrder: true,
allowBooleanAttributes: true,
ignoreAttributes: false,
ignoreDeclaration: true,
});
const firstCase = `<?xml version="1.0"?>
<root>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer pretium odio non ex hendrerit, eu convallis sapien ultricies <...> Sed sagittis at est auctor varius. Donec sit amet nibh sodales, varius nunc eu, tempus turpis. <...> Nulla gravida erat a tortor sollicitudin laoreet.</p>
<foo></foo>
</root>`;
const secondCase = `<?xml version="1.0"?>
<root>
<p>if (1 < 3) return text;</p>
</root>
`;
const jObj = xmlParser.parse(firstCase); // check first and second case
const xmlBuilder = new XMLBuilder({
ignoreAttributes: false,
preserveOrder: true,
});
const xmlContent = xmlBuilder.build(jObj);
console.log(xmlContent);
Output
In the first case:
jObj
[
{
"root": [
{
"p": [
{
"#text": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer pretium odio non ex hendrerit, eu convallis sapien ultricies"
},
{
"...": [
{
"#text": "Sed sagittis at est auctor varius. Donec sit amet nibh sodales, varius nunc eu, tempus turpis."
},
{
"...": [
{
"#text": "Nulla gravida erat a tortor sollicitudin laoreet."
}
]
},
{
"foo": []
}
]
}
]
}
]
}
]
<root><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer pretium odio non ex hendrerit, eu convallis sapien ultricies<...>Sed sagittis at est auctor varius. Donec sit amet nibh sodales, varius nunc eu, tempus turpis.<...>Nulla gravida erat a tortor sollicitudin laoreet.</...><foo></foo></...></p></root>
In the second case:
jObj
[
{
"root": [
{
"p": [
{
"#text": "if (1"
},
{
"": [],
":@": {
"@_3)": true,
"@_return": true,
"@_text;": true,
"@_</p": true
}
}
]
}
]
}
]
<root><p>if (1< 3) return text; </p></></p></root>
expected data
In the first case:
<root><p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer pretium odio non ex hendrerit, eu convallis sapien ultricies <...> Sed sagittis at est auctor varius. Donec sit amet nibh sodales, varius nunc eu, tempus turpis. <...> Nulla gravida erat a tortor sollicitudin laoreet.</p><foo></foo></root>
In the second case:
<root><p>if (1 < 3) return text;</p></root>
Would you like to work on this issue?
- Yes
- No
Bookmark this repository for further updates. Visit SoloThought to know about recent features.
- 主要语言
- JavaScript
- 星标
- 3.1k
- 派生
- 398
- 平均合并
- 3 天 9 小时
- 30 天内合并 PR
- 1
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
NaturalIntelligence/fast-xml-parser 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 70/100
NaturalIntelligence/fast-xml-parser#890 · 1 条评论 ·
维护者通常 4 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 65/100
NaturalIntelligence/fast-xml-parser#888 · 2 条评论 ·
维护者通常 4 天内回复
-
ignoreDeclaration does not ignore lower case doctype declaration可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
NaturalIntelligence/fast-xml-parser#870 · 2 条评论 ·
维护者通常 4 天内回复
-
CLI crashes with an uncaught exception when the input file is missing可能已有人在做 @troclaux 于 2 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 25/100
NaturalIntelligence/fast-xml-parser#894 · 1 条评论 ·
维护者通常 4 天内回复
-
Numeric character references (A, A) are not decoded unless htmlEntities is enabled可能已有人在做 @guocn 于 3 天前认领。 未关闭
难度 3/5 1-2 天 新手友好度 64/100
NaturalIntelligence/fast-xml-parser#892 · 2 条评论 ·
维护者通常 4 天内回复
查看 NaturalIntelligence/fast-xml-parser 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 76/100
bigcapitalhq/bigcapital#1544 · 1 条评论 ·
维护者通常 1 天内回复
-
help wanted kind/bug
难度 2/5 1-3 小时 新手友好度 78/100
meshery/meshery.io#3112 ·
维护者通常 2 天内回复
-
area:docs type:chore
难度 2/5 1-3 小时 新手友好度 82/100
bulkhead-labs/tailsuite#31 ·
-
dependencies javascript
难度 2/5 1-3 小时 新手友好度 70/100
gems-uff/noworkflow#470 ·
维护者通常 3 天内回复
-
product / auth product / console product / sites product / storage
难度 1/5 1 小时以内 新手友好度 84/100
维护者通常 1 天内回复