Say why an empty name is rejected, and finish what that removed
Tests / vet + fmt + tests (push) Failing after 42s
Tests / vet + fmt + tests (push) Failing after 42s
The reason given was wrong. A dot path did reach an empty-named field:
Fake("a.") returned it, Fake("a.b.") returned a nested one, and {..a.} bound
it. What was true is narrower — List never offered it, because an empty name
is no path segment — so the engine accepted spellings it would not advertise.
The message, the test comment and the README say that instead.
Two things the rejection finished off:
A {} token still reported "no field \"\"", pointing at a fix the loader now
rejects — two errors for one rule. It is told the name can never exist, like
an option token already is.
addressable is dead: both halves of "not empty and no dot" are now rejected
where a name is authored. Mutating it to panic leaves the suite green here
and panics on main, so it was live and is not. Keeping it would preserve the
silent-hiding this change removes — List quietly omitting a name rather than
New refusing it.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
+10
-4
@@ -120,9 +120,9 @@ func TestNewErrors(t *testing.T) {
|
||||
map[string]string{"a|b": `["1"]`},
|
||||
`category "a|b" contains "|"`,
|
||||
},
|
||||
// An empty name is reachable by no dot path, so List cannot advertise it and
|
||||
// Fake cannot ask for it — {} is the one spelling that reaches it, which is
|
||||
// the same trap {a.} is already rejected for.
|
||||
// An empty name is not a path segment, so List never offered it — while a
|
||||
// bare {}, a trailing dot in Fake("a.") and a {..a.} reference all reached
|
||||
// it. The engine accepted spellings it would never advertise.
|
||||
"empty field name": {
|
||||
map[string]string{"a": `{"format":"[{}]","":"VALUE"}`},
|
||||
`field "" is empty`,
|
||||
@@ -156,9 +156,15 @@ func TestNewErrors(t *testing.T) {
|
||||
map[string]string{"a": `{"format":"{..|..}"}`},
|
||||
"reference has no path",
|
||||
},
|
||||
// No field can be named "", so the token is told that rather than sent to
|
||||
// name one — the fix "no field" points at is itself a load error.
|
||||
"repeated empty arm": {
|
||||
map[string]string{"a": `{"format":"{|}"}`},
|
||||
`no field ""`,
|
||||
"a name is never empty",
|
||||
},
|
||||
"bare empty token": {
|
||||
map[string]string{"a": `{"format":"[{}]","x":["1"]}`},
|
||||
"a name is never empty",
|
||||
},
|
||||
}
|
||||
for name, c := range rejected {
|
||||
|
||||
Reference in New Issue
Block a user