Skip to content

Commit

Permalink
Restrict inline table to parent table's namespace
Browse files Browse the repository at this point in the history
Fixes naoina#7.
  • Loading branch information
kezhuw committed Dec 25, 2015
1 parent 7511716 commit 63190b1
Showing 1 changed file with 25 additions and 1 deletion.
26 changes: 25 additions & 1 deletion decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,30 @@ func (p *toml) SetTable(buf []rune, begin, end int) {
p.setTable(p.table, buf, begin, end)
}

func (p *toml) setInlineTable(t *ast.Table, buf []rune, begin, end int) {
name := string(buf[begin:end])
if val, exists := t.Fields[name]; exists {
switch v := val.(type) {
case *ast.Table:
p.Error(fmt.Errorf("inline table `%s' is conflict with %v table in line %d", name, v.Type, v.Line))
case *ast.KeyValue:
p.Error(fmt.Errorf("inline table `%s' is conflict with line %d", name, v.Line))
default:
p.Error(fmt.Errorf("BUG: inline table `%s' is in conflict but it's unknown type `%T'", name, v))
}
}
tbl := &ast.Table{
Line: p.line,
Name: name,
Type: ast.TableTypeNormal,
}
p.currentTable = tbl
if t.Fields == nil {
t.Fields = make(map[string]interface{})
}
t.Fields[name] = tbl
}

func (p *toml) setTable(t *ast.Table, buf []rune, begin, end int) {
name := string(buf[begin:end])
names := splitTableKey(name)
Expand Down Expand Up @@ -535,7 +559,7 @@ func (p *toml) StartInlineTable() {
p.stack = append(p.stack, &stack{p.key, p.currentTable})
buf := []rune(p.key)
if p.arr == nil {
p.setTable(p.currentTable, buf, 0, len(buf))
p.setInlineTable(p.currentTable, buf, 0, len(buf))
} else {
p.setArrayTable(p.currentTable, buf, 0, len(buf))
}
Expand Down

0 comments on commit 63190b1

Please sign in to comment.