json_path selects the wrong property for names ending in a newline
まだ誰も着手していません。
評価
調査の方向性
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
- フォーク
- 706
- 平均マージ
- 2日 1時間
- マージ済み PR(30日)
- 5
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python-jsonschema/jsonschema のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
python-jsonschema/jsonschema#1588 · コメント 2 件 ·
-
Iterator error contexts lose parent links and absolute paths再び着手できるかも @DawnofGenX が 18 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
python-jsonschema/jsonschema#1584 · コメント 3 件 ·
-
regex format checker crashes with RecursionError on deeply nested patterns対応中かも @DawnofGenX が 18 日前に担当しました。 オープン
難易度 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再び着手できるかも このイシューのプルリクエストはマージされずにクローズされました。 オープンNeeds Test Upstream
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
python-jsonschema/jsonschema#1511 · コメント 1 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 55/100
python-jsonschema/jsonschema#1590 · コメント 5 件 ·
python-jsonschema/jsonschema の issue をすべて見る
似ている issue
-
type-bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
push_gh-pages fails on master branch on forks対応中かも このイシューにリンクされたプルリクエストがオープン中、またはマージ済みです。 オープンgood first issue infrastructure
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
kuznia-rdzeni/coreblocks#1135 ·
-
good first issue server
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
メンテナーはふだん 1 日以内に返信
-
documentation priority: high
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
a-lex-s/mealie-telegram-bot#54 ·
メンテナーはふだん 1 日以内に返信