Several format checkers accept a single trailing newline (U+000A)
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 65/100
Línea de trabajo
Los checkers afectados están en jsonschema/_format.py, y las pruebas de regresión deben ir en tests/test_format.py. Empieza reproduciendo la fuga con el fragmento de FormatChecker del issue, y luego revisa los casos de optional/format/ de la suite oficial en busca de instancias con salto de línea final. El reportador ya tiene una rama, así que revisa el hilo de comentarios y pregunta a un maintainer antes de escribir un parche alternativo. Está terminado cuando cada formato listado rechaza un único \n final y la suite completa de pruebas sigue pasando.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Python
- Estrellas
- 5k
- Forks
- 700
- Merge medio
- 1 d 20 h
- PR fusionados (30 d)
- 6
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
-
Iterator error contexts lose parent links and absolute pathsQuizá libre de nuevo @DawnofGenX la tomó hace 10 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 10 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 ·
-
regex format checker crashes with ValueError on conflicting inline flagsPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
python-jsonschema/jsonschema#1558 · 2 comentarios ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
python-jsonschema/jsonschema#1547 ·
Todos los issues de python-jsonschema/jsonschema
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
common-workflow-language/cwl-utils#477 ·
Los mantenedores suelen responder en 1 día
-
Add dependabotAbiertofeat
Dificultad 2/5 Menos de una hora Aptitud para principiantes 72/100
open-nudge/opentemplate#204 ·
Los mantenedores suelen responder en 1 día
-
github-stale-ci-pr-closer: KV state is double-wrapped, never persists, and hits the depth-32 limitPosiblemente ocupada @VascoSch92 la tomó hoy. Abiertopriority:medium ready-for-dev
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
OpenHands/extensions#781 ·
Los mantenedores suelen responder en 1 día
-
bug good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
curriculum documentation quality
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
githubnext/gh-aw-workshop#4638 ·
Los mantenedores suelen responder en 1 día