Schema: reject duplicate fields in buildValue

This commit is contained in:
Adrià Arrufat
2026-05-25 20:22:44 +02:00
parent c59872bfb9
commit 7149bf3f5f

View File

@@ -246,7 +246,9 @@ fn buildValue(self: Schema, arena: std.mem.Allocator, pairs: []const KvPair, dia
try obj.ensureTotalCapacity(pairs.len);
for (pairs) |p| {
const v = try self.coerce(arena, p.key, p.value, diag);
try obj.put(p.key, v);
const gop = try obj.getOrPut(p.key);
if (gop.found_existing) return error.DuplicateField;
gop.value_ptr.* = v;
}
return .{ .object = obj };
}
@@ -745,6 +747,10 @@ test "parseValue: duplicate case-variants of the same field are rejected" {
error.DuplicateField,
click.parseValue(arena.allocator(), "{\"Selector\":\"#a\",\"selector\":\"#b\"}"),
);
try testing.expectError(
error.DuplicateField,
click.parseValue(arena.allocator(), "Selector='#a' selector='#b'"),
);
}
test "parseValue: setChecked defaults checked=true when omitted" {