json_path selects the wrong property for names ending in a newline
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 1/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 20/100
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Python
- Estrellas
- 5k
- Forks
- 700
- Merge medio
- 2 d 1 h
- PR fusionados (30 d)
- 5
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de python-jsonschema/jsonschema
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
python-jsonschema/jsonschema#1588 · 2 comentarios ·
-
Iterator error contexts lose parent links and absolute pathsQuizá libre de nuevo @DawnofGenX la tomó hace 14 días y no hay ningún pull request abierto. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
python-jsonschema/jsonschema#1584 · 3 comentarios ·
-
regex format checker crashes with RecursionError on deeply nested patternsPosiblemente ocupada @DawnofGenX la tomó hace 14 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
python-jsonschema/jsonschema#1538 · 1 comentario ·
-
is_duration raises an uncaught decimal.Overflow on a duration with a large exponentQuizá libre de nuevo Un pull request para esta issue se cerró sin fusionarse. AbiertoNeeds Test Upstream
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
python-jsonschema/jsonschema#1511 · 1 comentario ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 55/100
python-jsonschema/jsonschema#1590 ·
Todos los issues de python-jsonschema/jsonschema
Issues similares
-
`image_generation`: `max_retries` is ignored for OpenAI-compatible providers (always 2 retries)Posiblemente ocupada @ericz7900 la tomó hoy. Abiertollm translation
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
rheeloaded/paperpull#117 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 65/100
agenda-tech-brasil/agenda-tech-brasil#1619 · 1 comentario ·
-
process
Dificultad 1/5 1-3 horas Aptitud para principiantes 76/100
pyrite-wiki/pyrite#1036 ·
Los mantenedores suelen responder en 1 día