toml: decode date arrays with extra spaces that are not date-time separators (fix #25279) (#25335)

This commit is contained in:
Jorge Mireles 2025-09-18 02:48:22 -06:00 committed by GitHub
parent b2a985170d
commit c088cbdbd5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 0 deletions

View File

@ -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()!
}

View File

@ -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
}