Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

json_path selects the wrong property for names ending in a newline

未关闭
#1,589 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
1/5
预计耗时
1-3 小时
新手友好度
20/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
backend

调研方向

Start with the _JSON_PATH_COMPATIBLE_PROPERTY_PATTERN classification and TestJsonPathRendering, whose regression case and parser round-trip assertion are described in the issue. Check how the pattern classifies a property name ending in a newline, then run the path and exception tests. Done when json_path selects the property associated with the validation error and the regression test passes; a tested candidate patch is already linked in the issue.

由索引模型根据 Issue 内容生成。

描述

A property name ending in a newline is rendered with dot notation in ValidationError.json_path. Python's $ regex anchor matches just before a final newline, so "x\n" is treated as though it were an identifier. A consumer using jsonpath-ng then selects "x" rather than the invalid property "x\n".

Reproduced on main, commit c497561ea0a95f5aac09cd63d15eb1420eb7bbec, Python 3.12.4/macOS:

from jsonschema import Draft202012Validator
import jsonpath_ng

instance = {"x": "valid", "x\n": 1}
schema = {"properties": {"x\n": {"type": "string"}}}
error, = Draft202012Validator(schema).iter_errors(instance)

print(repr(error.json_path))
print([match.value for match in jsonpath_ng.parse(error.json_path).find(instance)])

Observed:

'$.x\n'
['valid']

Expected: the path selects the property actually associated with the validation error, whose value is 1. The existing bracket-notation branch produces "$['x\n']", which round-trips the property name correctly with the parser already used in this project's path-rendering tests.

Using fullmatch(elem) instead of match(elem) for _JSON_PATH_COMPATIBLE_PROPERTY_PATTERN fixes the classification. A regression case added to TestJsonPathRendering fails before the change and passes afterward, including its parser round-trip assertion. This is a follow-up edge case to #1389/#1390; the existing quote and backslash handling can stay as it is.

Validation of the candidate patch:

  • Path/exception tests: 76 passed (75 passed and the new test failed before the fix).
  • Full suite: 8,298 passed, 232 skipped.
  • Repository mypy check: passes (25 files).
  • Ruff: passes for the changed files.

The tested patch is available at https://github.com/shreyans-chowdry/jsonschema/commit/06208f1c7a671f5f2e10384e252932e81e951ed7.

This was found during source inspection and investigated, implemented, and tested with OpenAI Codex assistance. It was not observed in a production application. Since the repository currently restricts external PRs, this report includes the candidate patch for maintainer consideration; no upstream PR has been opened.

主要语言
Python
星标
5k
派生
700
平均合并
2 天 1 小时
30 天内合并 PR
5

环境准备

  • 没有 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

python-jsonschema/jsonschema 的其他 Issue

查看 python-jsonschema/jsonschema 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。