toml: fix implicit array allocation (#12553)

pull/12558/head
Larpon 2021-11-23 15:51:24 +01:00 committed by GitHub
parent 49cd1b3d59
commit 0779b5fd8e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 6 deletions

View File

@ -776,16 +776,19 @@ pub fn (mut p Parser) double_array_of_tables(mut table map[string]ast.Value) ? {
// Implicit allocation
if p.last_aot.len == 0 {
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'implicit allocation of array for dotted key `$dotted_key`.')
table[first.str()] = []ast.Value{}
p.last_aot = first
// We register this implicit allocation as *explicit* to be able to catch
// special cases like:
// https://github.com/BurntSushi/toml-test/blob/576db852/tests/invalid/table/array-implicit.toml
p.explicit_declared << first
t_arr = &(table[p.last_aot.str()] as []ast.Value)
t_arr << ast.Value(map[string]ast.Value{})
p.last_aot_index = t_arr.len - 1
mut nm := map[string]ast.Value{}
nm[last.str()] = []ast.Value{}
table[first.str()] = ast.Value(nm)
t_arr = &(nm[last.str()] as []ast.Value)
t_arr << p.array_of_tables_contents() ?
return
} else {
return error(@MOD + '.' + @STRUCT + '.' + @FN +
' nested array of tables key "$first" does not match "$p.last_aot". (excerpt): "...${p.excerpt()}..."')

View File

@ -17,8 +17,6 @@ const (
valid_value_exceptions = [
// Integer
'integer/long.toml', // TODO awaits BUG fix with strconv.parse_int('-9223372036854775808')
// Table
'table/array-implicit.toml',
// Date-time
'datetime/milliseconds.toml',
// Key