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

Whitespaces inside the quotation changes the behavior of `TZ="TIMEZONE"`

Abierto
#240 1 comentario 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
2/5
Tiempo estimado
1-3 horas
Aptitud para principiantes
45/100
Tipo de issue
Nueva funcionalidad
Claridad
Bien especificado
Estado de actividad
Estancado
Stack tecnológico
rust
Área
backend

Línea de trabajo

Comienza en src/items/timezone.rs y revisa el parser existente de TZ="..." y sus pruebas actuales. Comprueba los casos de espacios en blanco descritos en el issue y, después, verifica que el parser acepte el comportamiento propuesto para los espacios en blanco internos sin cambiar otras formas de zona horaria no relacionadas; se considera terminado cuando las pruebas relevantes pasan con los offsets previstos.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

This was a minor comment on https://github.com/uutils/parse_datetime/pull/232#issuecomment-3421283917 and it was suggested to create a separate issue for it

The following is the original copied here:


Hello, thanks to everybody for the great work.

I was studying this PR for a while and I was wondering that is there any reason (beyond performance) on why TZ="VALUE" is not relaxed with inner optional whitespaces (i.e TZ=" VALUE ")? Since such change passes all the current tests, this is a bit confusing to me.

This changes some behavior in an example like the following:

// prefixed whitespace
test(r#"TZ=" UTC-5:20:15""#, fixed_offset(0)); // current
test(r#"TZ=" UTC-5:20:15""#, fixed_offset(19215)); // with relaxed conditions

// prefixed whitespace
test(r#"TZ="UTC-5:20:15 ""#, Err(Backtrack(ContextError { context: [], cause: None }))); // current
test(r#"TZ="UTC-5:20:15 ""#, fixed_offset(19215)); // with relaxed conditions

Naturally, this can be generalized to the cases with :.

Whitespace relaxation can further improve in an unrelated example like: parse_datetime(" TZ=\"...\""). However in parse_datetime example, the user can easily just trim the input while removing the inner spaces of the quotation of this case is not as simple so that's why I think it's a quality improvement (if it is justified to begin with).

Example of changes that will relax this limitation:

diff --git a/src/items/timezone.rs b/src/items/timezone.rs
index 0414ee8..0009d17 100644
--- a/src/items/timezone.rs
+++ b/src/items/timezone.rs
@@ -16,6 +16,7 @@

 use jiff::tz::{Offset, TimeZone};
 use winnow::{
+    ascii::space0,
     combinator::{alt, delimited, opt, preceded, repeat},
     stream::AsChar,
     token::{one_of, take_while},
@@ -25,7 +26,12 @@ use winnow::{
 use super::primitive::{dec_uint, plus_or_minus};

 pub(super) fn parse(input: &mut &str) -> ModalResult<TimeZone> {
-    delimited("TZ=\"", preceded(opt(':'), alt((posix, iana))), '"').parse_next(input)
+    delimited(
+        ("TZ=\"", space0),
+        preceded(opt((':', space0)), alt((posix, iana))),
+        (space0, "\""),
+    )
+    .parse_next(input)
 }

 /// Parse a posix (proleptic) timezone string (e.g., "UTC7", "JST-9").
Lenguaje dominante
Rust
Estrellas
37
Forks
42
Merge medio
17 h 48 min
PR fusionados (30 d)
8

Preparar el entorno

Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.

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 uutils/parse_datetime

Todos los issues de uutils/parse_datetime

Issues similares

Más issues de Rust

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.