From c088cbdbd5193496976824740b404cb8957a05d4 Mon Sep 17 00:00:00 2001 From: Jorge Mireles Date: Thu, 18 Sep 2025 02:48:22 -0600 Subject: [PATCH] toml: decode date arrays with extra spaces that are not date-time separators (fix #25279) (#25335) --- vlib/toml/parser/parser.v | 8 ++++++++ vlib/toml/tests/encode_and_decode_test.v | 11 +++++++++++ 2 files changed, 19 insertions(+) diff --git a/vlib/toml/parser/parser.v b/vlib/toml/parser/parser.v index 727fb91c06..021b18aab4 100644 --- a/vlib/toml/parser/parser.v +++ b/vlib/toml/parser/parser.v @@ -1420,6 +1420,14 @@ pub fn (mut p Parser) date_time() !ast.DateTimeType { if p.tok.lit.starts_with('T') || p.tok.lit.starts_with('t') { lit += p.tok.lit[0].ascii_str() //'T' or 't' } else { + peek := p.peek(0)! + if peek.kind != .number { + // return early as date for strings yyyy-mm-dd_X... (_ is space, X is not numeric) + return ast.Date{ + text: lit + pos: pos + } + } lit += p.tok.lit p.next()! } diff --git a/vlib/toml/tests/encode_and_decode_test.v b/vlib/toml/tests/encode_and_decode_test.v index 6ace626c98..059b9e5997 100644 --- a/vlib/toml/tests/encode_and_decode_test.v +++ b/vlib/toml/tests/encode_and_decode_test.v @@ -326,3 +326,14 @@ fn test_unsupported_type() { assert err.msg() == 'Doc.decode: expected struct, found string' } } + +fn test_date_array_decode_with_spaces() { + // test space after yyyy-mm-dd is not date-time separator but white to consume. issue # 25279 + s := ' +dates = [ 1979-05-27 , 2022-12-31 ] +' + a := Arrs{ + dates: [toml.Date{'1979-05-27'}, toml.Date{'2022-12-31'}] + } + assert toml.decode[Arrs](s)! == a +}