Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json: respect duplicate_field_behavior in std.json.Value.jsonParse #20430

Merged
merged 1 commit into from
Jul 3, 2024

Conversation

Techatrix
Copy link
Contributor

This test would previously pass successfully even though it shouldn't:

const std = @import("std");
test {
    const parsed_value = try std.json.parseFromSlice(std.json.Value, std.testing.allocator,
        \\{
        \\  "foo": 1,
        \\  "foo": 2
        \\}
    , .{ .duplicate_field_behavior = .@"error" });
    defer parsed_value.deinit();
    try std.testing.expectEqual(2, parsed_value.value.object.get("foo").?.integer);
}

@@ -28,7 +28,9 @@ fn testLowLevelScanner(s: []const u8) !void {
}
}
fn testHighLevelDynamicParser(s: []const u8) !void {
var parsed = try parseFromSlice(Value, testing.allocator, s, .{});
var parsed = try parseFromSlice(Value, testing.allocator, s, .{
.duplicate_field_behavior = .use_first,
Copy link
Sponsor Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because of these tests. Duplicate field names are still valid JSON grammer and MUST therefore be successfully parsed according to RFC 8259. See nst/JSONTestSuite#56

@andrewrk andrewrk merged commit 8f7b50e into ziglang:master Jul 3, 2024
10 checks passed
@Techatrix Techatrix deleted the json-duplicate-field branch July 3, 2024 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants