xml.dom.minidom: serializing a comment ending in '-' silently produces non-well-formed XML
还没有人认领这个 Issue。
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Bug report
Bug description:
xml.dom.minidom guards comment serialization against -- (illegal inside an XML comment): Comment.writexml raises ValueError if "--" in self.data (test testSerializeCommentNodeWithDoubleHyphen). It misses a comment whose data ends with -: the trailing - fuses with the closing --> into --->, which contains --.
import xml.dom.minidom as m
doc = m.getDOMImplementation().createDocument(None, None, None)
doc.appendChild(doc.createComment("see note-"))
out = doc.toxml() # '<?xml version="1.0" ?><!--see note--->'
m.parseString(out) # xml.parsers.expat.ExpatError: not well-formed
minidom silently emits XML it cannot reparse. The existing -- guard already takes the stance that serialization must fail loudly on comment content it cannot represent; the trailing-- case is a gap in that guard.
CPython versions tested on:
CPython main
Operating systems tested on:
Linux, macOS
Linked PRs
- gh-156813
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 xml.dom.minidom 的 Comment.writexml 实现和现有的名为 testSerializeCommentNodeWithDoubleHyphen 的测试开始。复现以 '-' 结尾的注释的序列化,并运行 minidom 测试;完成的标准是,末尾带连字符的无效情况与包含 '--' 的注释一样被一致拒绝。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- backend
- Issue 类型
- 缺陷
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 活跃度
- 停滞
- 描述清晰度
- 描述清楚
- 新手友好度
- 35/100