fix: empty changeset must serialize as [] not null (white-screen after snapshot)
toChangesetResponse initialises updates/prunes/readOnly so a zone matching its template exactly (e.g. right after 'create template from zone') marshals arrays, not null. DiffView/DomainDiffPage also normalise null defensively. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01BwxdSt4reTm7Dj1oxRvpP3
This commit is contained in:
@@ -136,3 +136,20 @@ func TestApplyBadUUID(t *testing.T) {
|
||||
t.Fatalf("expected 400 for bad uuid, got %d", w.Code)
|
||||
}
|
||||
}
|
||||
|
||||
// TestChangesetResponseEmptyMarshalsToArrays guards the белый-экран bug: an
|
||||
// empty changeset (zone matches its template exactly, e.g. right after a
|
||||
// snapshot) must marshal updates/prunes/readOnly as [] not null — a nil slice
|
||||
// becomes JSON null and crashes the client's .length/.map calls.
|
||||
func TestChangesetResponseEmptyMarshalsToArrays(t *testing.T) {
|
||||
b, err := json.Marshal(toChangesetResponse(diff.Changeset{}))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
s := string(b)
|
||||
for _, want := range []string{`"updates":[]`, `"prunes":[]`, `"readOnly":[]`} {
|
||||
if !strings.Contains(s, want) {
|
||||
t.Fatalf("expected %s in %s", want, s)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user