Escaping `XmlNameProcessors` write a colon in XML names as-is, producing output that can not be read back
还没有人认领这个 Issue。
评估
调研方向
查看 Base64NameProcessor 和 ReplaceNameProcessor。修改正则表达式模式 VALID_XML_NAME 和允许的字符集以排除冒号,使 a:b 这类名称被转义或替换。相应地更新 encodeName() 方法。添加往返测试,验证包含冒号的名称可序列化为有效XML,且反序列化时不会抛出 StreamReadException。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
Both escaping processors from XmlNameProcessors treat a colon as a valid XML name character, so a name that contains one is written out verbatim:
Base64NameProcessor.VALID_XML_NAMEis[a-zA-Z_:]([a-zA-Z0-9_:.-])*, i.e. a name holding a colon counts as already valid and is not escapedReplaceNameProcessorkeeps:in both of its allowed sets (^[^a-zA-Z_:],[^a-zA-Z0-9_:-])
Output is namespace-aware, though, so the colon comes back as a prefix that nothing declares and the document can no longer be read by this module:
<DTO><badMap><a:b>xyz</a:b></badMap></DTO>
tools.jackson.core.exc.StreamReadException:
Undeclared namespace prefix "a"
at [row,col {unknown-source}]: [1,18]
at [Source: (String)"<DTO><badMap><a:b>xyz</a:b></badMap></DTO>"; line: 1, column: 19]
Caused by: com.ctc.wstx.exc.WstxParsingException: Undeclared namespace prefix "a"
Keys like a:b:c or :leading are not even well-formed, so they fail in the Stax reader before namespace resolution.
The javadoc of both processors lists the colon as "only exposed if underlying parser is in non-namespace-aware mode", but encoding has no knowledge of which parser will read the result back, and newAlwaysOnBase64Processor() already handles the same keys cleanly. Round-tripping names that are not valid XML names is what these two processors exist for, so the colon looks like an oversight in the allowed sets rather than a deliberate exception.
Version information
3.3.0-SNAPSHOT (3.x). The allowed sets have looked this way since the mechanism was added (#531), so 3.0/3.1/3.2 and 2.x behave the same.
Reproduction
public static class DTO {
public Map<String, String> badMap = new HashMap<>();
}
private XmlFactory xmlFactory(XmlNameProcessor nameProcessor) {
return XmlFactory.builder().xmlNameProcessor(nameProcessor).build();
}
@Test
public void colonInNameRoundTrips() throws Exception {
XmlMapper mapper = XmlMapper.builder(
xmlFactory(XmlNameProcessors.newBase64Processor())).build();
DTO dto = new DTO();
dto.badMap.put("a:b", "xyz");
String xml = mapper.writeValueAsString(dto);
// writes <DTO><badMap><a:b>xyz</a:b></badMap></DTO>
mapper.readValue(xml, DTO.class); // StreamReadException: Undeclared namespace prefix "a"
}
Same for newReplacementProcessor(), which writes <a:b> rather than replacing the colon. newAlwaysOnBase64Processor() is fine, since it escapes every name.
Expected behavior
A name containing a colon should be escaped (base64, still a lossless round trip) or replaced, like any other character that cannot appear in a written XML name, so that what these processors write can be read back.
Only encodeName() would need to change: decodeName() keys off the prefix for base64 and is a no-op for replacement, so names read from a non-namespace-aware parser are still passed through untouched.
Additional context
PR #921 has the fix plus round-trip tests. Targeted at 3.x since it changes what gets written for these names.
- 主要语言
- Java
- 星标
- 636
- 派生
- 250
- 平均合并
- 7 小时 10 分钟
- 30 天内合并 PR
- 8
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
FasterXML/jackson-dataformat-xml 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 55/100
-
难度 4/5 3-5 天 新手友好度 45/100
FasterXML/jackson-dataformat-xml#931 · 3 条评论 ·
-
XmlMapper with `FAIL_ON_UNKNOWN_PROPERTIES` fails on whitespace-only element可能已有人在做 @arimu1 于 89 天前认领。 未关闭to-evaluate
难度 3/5 1-2 天 新手友好度 68/100
-
3.x
难度 4/5 3-5 天 新手友好度 25/100
FasterXML/jackson-dataformat-xml#787 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 35/100
FasterXML/jackson-dataformat-xml#712 · 3 条评论 ·
查看 FasterXML/jackson-dataformat-xml 的全部 Issue
相似的 Issue
-
Cleanup: restore the interrupt flag in AiFailureAnalyzer可能已有人在做 @Rishankgupta08 今天认领。 未关闭good first issue
难度 2/5 1-3 小时 新手友好度 82/100
seleniumboot/selenium-boot#258 · 1 条评论 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 70/100
dense-analysis/ale#5181 ·
-
bug subsystem:agent-harness triage
难度 2/5 1-3 小时 新手友好度 76/100
ShaftHQ/SHAFT_ENGINE#8043 ·
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 88/100
johanhaleby/occurrent#1505 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复