mirror of
https://github.com/ziglang/zig.git
synced 2026-02-18 15:31:48 +00:00
std/json: Fix premature closing brace being considered valid JSON
return error from StreamingParser when reading closing brace when expecting value for an object key
This commit is contained in:
parent
4f71852c10
commit
e902c19c0e
@ -623,7 +623,7 @@ pub const StreamingParser = struct {
|
|||||||
|
|
||||||
.ObjectSeparator => switch (c) {
|
.ObjectSeparator => switch (c) {
|
||||||
':' => {
|
':' => {
|
||||||
p.state = .ValueBegin;
|
p.state = .ValueBeginNoClosing;
|
||||||
p.after_string_state = .ValueEnd;
|
p.after_string_state = .ValueEnd;
|
||||||
},
|
},
|
||||||
0x09, 0x0A, 0x0D, 0x20 => {
|
0x09, 0x0A, 0x0D, 0x20 => {
|
||||||
@ -1205,6 +1205,13 @@ test "json.token mismatched close" {
|
|||||||
try testing.expectError(error.UnexpectedClosingBrace, p.next());
|
try testing.expectError(error.UnexpectedClosingBrace, p.next());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "json.token premature object close" {
|
||||||
|
var p = TokenStream.init("{ \"key\": }");
|
||||||
|
try checkNext(&p, .ObjectBegin);
|
||||||
|
try checkNext(&p, .String);
|
||||||
|
try testing.expectError(error.InvalidValueBegin, p.next());
|
||||||
|
}
|
||||||
|
|
||||||
/// Validate a JSON string. This does not limit number precision so a decoder may not necessarily
|
/// Validate a JSON string. This does not limit number precision so a decoder may not necessarily
|
||||||
/// be able to decode the string even if this returns true.
|
/// be able to decode the string even if this returns true.
|
||||||
pub fn validate(s: []const u8) bool {
|
pub fn validate(s: []const u8) bool {
|
||||||
|
|||||||
@ -76,6 +76,12 @@ test "y_trailing_comma_after_empty" {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test "n_object_closed_missing_value" {
|
||||||
|
try err(
|
||||||
|
\\{"a":}
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
test "y_array_arraysWithSpaces" {
|
test "y_array_arraysWithSpaces" {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user