From e31e77b8a3b3efcdd759faef6d9ac9ed2e5d2fde Mon Sep 17 00:00:00 2001 From: M Date: Mon, 31 Aug 2026 22:07:47 +0200 Subject: [PATCH] Tests for an empty field name MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit A field named "" loads, and a bare {} token renders it, but no dot path can reach it — List hides it and Fake cannot ask for it. {a.} is already rejected for the same reason, so the two spellings disagree about the same mistake. Co-Authored-By: Claude Opus 5 --- bound_test.go | 11 ++++++----- edge_test.go | 7 +++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/bound_test.go b/bound_test.go index 6b0468b..fc68936 100644 --- a/bound_test.go +++ b/bound_test.go @@ -656,12 +656,13 @@ func TestDeepPathsUnderOneHeadStayIndependentWhereTheyDiverge(t *testing.T) { } func TestEmptyPathSegmentIsRejected(t *testing.T) { - // "{a.}", "{.b}" and "{a..b}" are unfinished paths. A field really named "" - // would otherwise make them resolve, which reads as a typo that worked. + // "{a.}", "{.b}" and "{a..b}" are unfinished paths, and the segment naming + // nothing is reported as that rather than as a missing field. An empty name is + // rejected where it is authored, so no data can make these resolve. rejected := map[string]string{ - "trailing dot": `{"format":"[{a.}]","a":{"format":"x","":["V"]}}`, - "leading dot": `{"format":"[{.b}]","":{"format":"{b}","b":["V"]}}`, - "double dot": `{"format":"[{a..b}]","a":{"format":"x","":{"format":"{b}","b":["V"]}}}`, + "trailing dot": `{"format":"[{a.}]","a":{"format":"x"}}`, + "leading dot": `{"format":"[{.b}]","a":{"format":"{b}","b":["V"]}}`, + "double dot": `{"format":"[{a..b}]","a":{"format":"x"}}`, } for name, file := range rejected { _, err := New([]string{writeData(t, map[string]string{"cat": file})}) diff --git a/edge_test.go b/edge_test.go index 806416c..2ee4eb9 100644 --- a/edge_test.go +++ b/edge_test.go @@ -120,6 +120,13 @@ 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. + "empty field name": { + map[string]string{"a": `{"format":"[{}]","":"VALUE"}`}, + `field "" is empty`, + }, "folder name with a paren": { map[string]string{"a(b/cat": `["1"]`}, `folder "a(b" contains "("`,