fix(parser): reject an array-of-tables header extending a frozen inline table
Assisted-by: GLM 5.3
This commit is contained in:
@@ -41,6 +41,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
|
||||
### Fixed
|
||||
|
||||
- An array-of-tables header whose path runs through an inline table
|
||||
(`a = {b = {}}` followed by `[[a.b.c]]`) is rejected. The frozen-inline-table
|
||||
check covered `[table]` headers and dotted keys but not the intermediate
|
||||
steps of an array-of-tables header, so such a document silently extended the
|
||||
inline table.
|
||||
- A float with an exponent marker but no digits (`1e`, `0.0E`) is rejected;
|
||||
the exponent requires at least one digit.
|
||||
- A date-time offset outside 00:00 through 23:59 is rejected; such offsets
|
||||
|
||||
@@ -487,6 +487,9 @@ func TestRejectsInlineTableExtension(t *testing.T) {
|
||||
"by header": "a = { b = 1 }\n[a.c]\nx = 2\n",
|
||||
"by dotted key": "a = { b = 1 }\na.c = 2\n",
|
||||
"header over it": "a = { b = 1 }\n[a]\nx = 2\n",
|
||||
// The frozen check must cover the intermediate steps of an array-of-tables
|
||||
// header, not only the leaf: [[a.b.c]] walks through a and a.b.
|
||||
"by nested array header": "a = { b = {} }\n[[a.b.c]]\nx = 2\n",
|
||||
}
|
||||
for name, doc := range cases {
|
||||
if _, err := Parse([]byte(doc)); err == nil {
|
||||
|
||||
@@ -171,7 +171,12 @@ func (p *parser) tableAt(key []string) (map[string]any, error) {
|
||||
|
||||
func (p *parser) appendArrayTable(key []string) (map[string]any, error) {
|
||||
parent := p.root
|
||||
path := make([]string, 0, len(key))
|
||||
for _, k := range key[:len(key)-1] {
|
||||
path = append(path, k)
|
||||
if p.frozen[pathKey(path)] {
|
||||
return nil, p.errf("cannot extend inline table %q", strings.Join(path, "."))
|
||||
}
|
||||
existing, ok := parent[k]
|
||||
if !ok {
|
||||
next := map[string]any{}
|
||||
|
||||
Reference in New Issue
Block a user