Attribute values are not normalized as XML 1.0 section 3.3.3 requires
维护者通常 4 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 48/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- javascript
- 领域
- backend
调研方向
Start by reading the XMLParser attribute handling and entity decoding paths, then check issue #330 for the existing behavior around preserving newlines. The report says normalization must happen before entity and character references are decoded and may need to be opt-in. Done means literal attribute whitespace normalizes to spaces while a decoded character reference preserves its newline; add coverage for both forms.
由索引模型根据 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
XMLParser does not apply the attribute-value normalization of XML 1.0, section 3.3.3. A literal line feed or tab in an attribute value is kept as is, but the spec says that a conforming processor replaces each literal whitespace character (#x20, #xD, #xA, #x9) with a space, and only a character reference such as adds the character itself.
Because the parser keeps the literal characters, the two forms cannot be told apart once character references are decoded (htmlEntities: true or an entityDecoder): a="x y" and an attribute with a real line break both become "x\ny". An application that writes the value back has no way to know whether the source meant a space or a line feed.
I found no option for this. #330 asked for the opposite (keeping newlines) in 2021, and that is the current behavior, so a change would probably have to be opt-in, for example an option such as normalizeAttributeValues: true. The normalization would have to happen before entity and character references are decoded.
Input
<r a="x
y"/>
Code
import { XMLParser } from "fast-xml-parser"; // 5.12.0
const parser = new XMLParser({ ignoreAttributes: false, attributeNamePrefix: "" });
parser.parse('<r a="x\ny"/>').r.a; // "x\ny"
parser.parse('<r a="x\ty"/>').r.a; // "x\ty"
parser.parse('<r a="x\r\ny"/>').r.a; // "x\ny"
parser.parse('<r a="x y"/>').r.a; // "x y" (numeric references are not decoded by default, see #892)
Output
"x\ny"
"x\ty"
"x\ny"
expected data
"x y"
"x y"
"x y"
"x\ny" // for a="x y", once numeric references are decoded
For comparison, @xmldom/xmldom returns "x y" for the first two inputs and "x\ny" for a="x y".
Would you like to work on this issue?
- Yes
- No
- 主要语言
- JavaScript
- 星标
- 3.1k
- 派生
- 410
- 平均合并
- 4 天 15 小时
- 30 天内合并 PR
- 8
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
NaturalIntelligence/fast-xml-parser 的其他 Issue
-
A processing instruction with no target passes validation, then the builder prints invalid XML可能已有人在做 @bardrop 于 1 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
NaturalIntelligence/fast-xml-parser#927 · 2 条评论 ·
维护者通常 4 天内回复
-
XMLValidator accepts double hyphens inside comments可能已有人在做 @Sskift 于 16 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 74/100
NaturalIntelligence/fast-xml-parser#903 · 3 条评论 ·
维护者通常 4 天内回复
-
XMLValidator accepts raw < and & in attribute values可能已有人在做 @jeromeyyy 于 14 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
NaturalIntelligence/fast-xml-parser#900 · 3 条评论 ·
维护者通常 4 天内回复
-
getMetaDataSymbol() declares a boxed Symbol可能已有人在做 @chiragbitoni 于 4 天前认领。 未关闭
难度 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 天内回复
查看 NaturalIntelligence/fast-xml-parser 的全部 Issue
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 84/100
-
难度 2/5 1-3 小时 新手友好度 83/100
-
Extended search drops any query term that contains a line break可能已有人在做 @goranai 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
-
难度 2/5 1-3 小时 新手友好度 72/100
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复