Skip to content

Commit db65b65

Browse files
authored
toml: disallow spacing between (array of tables) key syntax (#12382)
1 parent c3b389c commit db65b65

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

vlib/toml/parser/parser.v

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,23 +368,37 @@ pub fn (mut p Parser) root_table() ? {
368368
}
369369
.lsbr {
370370
p.check(.lsbr) ? // '[' bracket
371+
mut peek_tok := p.peek_tok
372+
373+
// Disallow `[ [table]]`
374+
if p.tok.kind in parser.space_formatting {
375+
peek_tok = p.peek_over(1, parser.space_formatting) ?
376+
if peek_tok.kind == .lsbr {
377+
return error(@MOD + '.' + @STRUCT + '.' + @FN +
378+
' unexpected "$p.tok.kind" "$p.tok.lit" at this (excerpt): "...${p.excerpt()}..."')
379+
}
380+
}
381+
382+
// Allow `[ d.e.f]`
371383
p.ignore_while(parser.space_formatting)
372384

373-
mut peek_tok := p.peek_tok
374385
// Peek forward as far as we can skipping over space formatting tokens.
375386
peek_tok = p.peek_over(1, parser.space_formatting) ?
376387

377388
if p.tok.kind == .lsbr {
389+
// Parse `[[table]]`
378390
p.array_of_tables(mut &p.root_map) ?
379391
p.skip_next = true // skip calling p.next() in coming iteration
380392
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'leaving double bracket at "$p.tok.kind" "$p.tok.lit". NEXT is "$p.peek_tok.kind "$p.peek_tok.lit"')
381393
} else if peek_tok.kind == .period {
394+
// Parse `[d.e.f]`
382395
p.ignore_while(parser.space_formatting)
383396
p.root_map_key = p.dotted_key() ?
384397
p.ignore_while(parser.space_formatting)
385398
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'setting root map key to `$p.root_map_key` at "$p.tok.kind" "$p.tok.lit"')
386399
p.expect(.rsbr) ?
387400
} else {
401+
// Parse `[key]`
388402
key := p.key() ?
389403
p.root_map_key = key.str()
390404
util.printdbg(@MOD + '.' + @STRUCT + '.' + @FN, 'setting root map key to `$p.root_map_key` at "$p.tok.kind" "$p.tok.lit"')

vlib/toml/tests/burntsushi.toml-test_test.v

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const (
1717
'table/duplicate.toml',
1818
'table/array-implicit.toml',
1919
'table/injection-2.toml',
20-
'table/llbrace.toml',
2120
'table/injection-1.toml',
2221
'table/duplicate-table-array.toml',
2322
// Array

0 commit comments

Comments
 (0)