Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

Several format checkers accept a single trailing newline (U+000A)

Abierto Apto para principiantes
#1,588 2 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
65/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python
Área
devtools

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

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de python-jsonschema/jsonschema

Todos los issues de python-jsonschema/jsonschema

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.