Several format checkers accept a single trailing newline (U+000A)
还没有人认领这个 Issue。
评估
调研方向
受影响的检查器位于 jsonschema/_format.py,回归测试应添加到 tests/test_format.py。先用 issue 中的 FormatChecker 代码片段复现这个泄漏,然后检查官方测试套件中 optional/format/ 的用例,查看末尾带换行符的实例。报告者已经有一个分支,因此请先查看评论区,并在编写竞争性补丁之前征求维护者的意见。当所有列出的格式都会拒绝末尾单个 \n,且完整测试套件仍然通过时,即视为完成。
由索引模型根据 Issue 内容生成。
描述
The date-time, time, uri, uri-reference, iri,
iri-reference, and hostname/host-name checkers each accept a
single trailing newline (U+000A), although none of the corresponding
grammars allow one.
from jsonschema import FormatChecker
c = FormatChecker()
c.check("1985-04-12T23:20:50Z\n", "date-time") # accepted
c.check("http://foo.bar/\n", "uri") # accepted
c.check("example.com\n", "hostname") # accepted
The official test suite now asserts these are invalid. The matching
"trailing newline is invalid" cases appear under each draft's
optional/format/ for all of the formats above (e.g.
date-time.json, time.json, uri.json, uri-reference.json,
iri.json, iri-reference.json, hostname.json). The instance without
the trailing newline remains valid in every case, so the leak is the
bare trailing \n and nothing else.
Why it happens
Each of these checkers delegates to an external validator package
(rfc3339-validator, rfc3987 / rfc3986_validator /
rfc3987_syntax, fqdn). Those packages each accept exactly one
trailing \n — other stray whitespace is already rejected — so the
behavior is asymmetric:
"1985-04-12T23:20:50Z" # valid
"1985-04-12T23:20:50Z\n" # accepted (leak)
"1985-04-12T23:20:50Z\r\n" # rejected
"1985-04-12T23:20:50Z " # rejected
" 1985-04-12T23:20:50Z" # rejected
The vendored copy of the official suite shipped in json/ predates these
cases, so CI does not currently catch it. I verified there is no
format case in the pinned suite whose data contains a newline, so a
guard here does not change any currently-pinned expectation.
Fix
A small shape guard in jsonschema/_format.py that rejects a trailing
newline before delegating, shared by every affected checker and applied
to both the rfc3987 and its rfc3986/rfc3987_syntax fallback
branches, plus regression tests in tests/test_format.py that mirror the
official-suite instances. Keeping the guard in jsonschema (rather than
relying on each upstream library) covers all the delegated
implementations in one place.
I've prepared it as a branch for cherry-pick:
https://github.com/Master-Norna/jsonschema/compare/master...fix/formats-trailing-newline
The diff is small (~30 lines in _format.py, new test class in
test_format.py) and I have it passing the full suite plus a re-run of
the official suite's new format cases.
- 主要语言
- Python
- 星标
- 5k
- 派生
- 694
- 平均合并
- 1 天 20 小时
- 30 天内合并 PR
- 6
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 没有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
python-jsonschema/jsonschema 的其他 Issue
-
Iterator error contexts lose parent links and absolute paths可能重新可做 @DawnofGenX 于 9 天前认领,目前没有进行中的 PR。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
python-jsonschema/jsonschema#1584 · 3 条评论 ·
-
regex format checker crashes with RecursionError on deeply nested patterns可能已有人在做 @DawnofGenX 于 9 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
python-jsonschema/jsonschema#1538 · 1 条评论 ·
-
is_duration raises an uncaught decimal.Overflow on a duration with a large exponent可能重新可做 关联的 PR 已关闭且未合并。 未关闭Needs Test Upstream
难度 2/5 1-3 小时 新手友好度 78/100
python-jsonschema/jsonschema#1511 · 1 条评论 ·
-
regex format checker crashes with ValueError on conflicting inline flags可能已有人在做 关联的 PR 仍在进行中或已合并。 未关闭
难度 3/5 1-2 天 新手友好度 68/100
python-jsonschema/jsonschema#1558 · 2 条评论 ·
-
难度 4/5 3-5 天 新手友好度 45/100
python-jsonschema/jsonschema#1547 ·
查看 python-jsonschema/jsonschema 的全部 Issue
相似的 Issue
-
good first issue
难度 2/5 1-3 小时 新手友好度 85/100
btclib-org/btclib-node#1955 ·
维护者通常 1 天内回复
-
documentation v0.9.2
难度 2/5 半天 新手友好度 72/100
khuisman/mcp-gee-sweet#1033 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
ossf/cve-bin-tool#5966 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
维护者通常 2 天内回复
-
write_iceberg ignores the table's write.parquet.compression-codec property可能已有人在做 @YuangGao 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
Eventual-Inc/Daft#7606 ·
维护者通常 1 天内回复