json_path selects the wrong property for names ending in a newline
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 1/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 20/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 5k
- Fork
- 706
- Merge trung bình
- 2 ngày 1 giờ
- Pull request đã merge (30 ngày)
- 5
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của python-jsonschema/jsonschema
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
python-jsonschema/jsonschema#1588 · 2 bình luận ·
-
Iterator error contexts lose parent links and absolute pathsCó thể làm lại được @DawnofGenX đã nhận 17 ngày trước và không có pull request nào đang mở. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
python-jsonschema/jsonschema#1584 · 3 bình luận ·
-
regex format checker crashes with RecursionError on deeply nested patternsCó thể đã có người làm @DawnofGenX đã nhận 17 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
python-jsonschema/jsonschema#1538 · 1 bình luận ·
-
is_duration raises an uncaught decimal.Overflow on a duration with a large exponentCó thể làm lại được Pull request cho issue này đã bị đóng mà không được merge. Đang mởNeeds Test Upstream
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
python-jsonschema/jsonschema#1511 · 1 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 55/100
python-jsonschema/jsonschema#1590 · 5 bình luận ·
Tất cả issue của python-jsonschema/jsonschema
Issue tương tự
-
[Resource]: glyphcss-diagramsĐang mởresource-submission validation-passed
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
hesreallyhim/awesome-claude-code#3214 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
room-commons replace accepts an empty old string and silently prepends the new text to the pageĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
doobidoo/mcp-memory-service#1650 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 82/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
ml-explore/mlx-lm#2002 ·
Maintainer thường phản hồi trong vòng 2 ngày