diff options
| author | Matthew Borkowski <matthew.h.borkowski@gmail.com> | 2021-05-13 05:11:28 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-05-13 11:11:28 +0200 |
| commit | e902c19c0e2bf7f0e9bc83b2c58d19ec024d56db (patch) | |
| tree | de1f648b1339d0c01e799d9d40e7fb602b282b8a /lib/std/json.zig | |
| parent | 4f71852c103f8dbf6ce78b36e5abd41a0c4ccf06 (diff) | |
| download | zig-e902c19c0e2bf7f0e9bc83b2c58d19ec024d56db.tar.gz zig-e902c19c0e2bf7f0e9bc83b2c58d19ec024d56db.zip | |
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
Diffstat (limited to 'lib/std/json.zig')
| -rw-r--r-- | lib/std/json.zig | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/std/json.zig b/lib/std/json.zig index ed26c13229..7515f8682d 100644 --- a/lib/std/json.zig +++ b/lib/std/json.zig @@ -623,7 +623,7 @@ pub const StreamingParser = struct { .ObjectSeparator => switch (c) { ':' => { - p.state = .ValueBegin; + p.state = .ValueBeginNoClosing; p.after_string_state = .ValueEnd; }, 0x09, 0x0A, 0x0D, 0x20 => { @@ -1205,6 +1205,13 @@ test "json.token mismatched close" { 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 /// be able to decode the string even if this returns true. pub fn validate(s: []const u8) bool { |
