| author | |
| committer | |
| log | 4c116841840bfa7f0068bef23984dd832da8a54d |
| tree | eef882bbd8b87ab483b47b7e5b01951fab1a3c81 |
| parent | f68d3c63df0486c7039732ef442c87fcd7c6fc57 |
| signature |
2 files changed, 8 insertions(+), 1 deletions(-)
lib/std/json.zig+2-1| ... | ... | @@ -1384,7 +1384,7 @@ fn ParseInternalErrorImpl(comptime T: type, comptime inferred_types: []const typ |
| 1384 | 1384 | return errors; |
| 1385 | 1385 | }, |
| 1386 | 1386 | .Array => |arrayInfo| { |
| 1387 | return error{ UnexpectedEndOfJson, UnexpectedToken } || TokenStream.Error || | |
| 1387 | return error{ UnexpectedEndOfJson, UnexpectedToken, LengthMismatch } || TokenStream.Error || | |
| 1388 | 1388 | UnescapeValidStringError || |
| 1389 | 1389 | ParseInternalErrorImpl(arrayInfo.child, inferred_types ++ [_]type{T}); |
| 1390 | 1390 | }, |
| ... | ... | @@ -1625,6 +1625,7 @@ fn parseInternal( |
| 1625 | 1625 | if (arrayInfo.child != u8) return error.UnexpectedToken; |
| 1626 | 1626 | var r: T = undefined; |
| 1627 | 1627 | const source_slice = stringToken.slice(tokens.slice, tokens.i - 1); |
| 1628 | if (r.len != stringToken.decodedLength()) return error.LengthMismatch; | |
| 1628 | 1629 | switch (stringToken.escapes) { |
| 1629 | 1630 | .None => mem.copy(u8, &r, source_slice), |
| 1630 | 1631 | .Some => try unescapeValidString(&r, source_slice), |
lib/std/json/test.zig+6| ... | ... | @@ -2238,6 +2238,12 @@ test "parse into struct with no fields" { |
| 2238 | 2238 | try testing.expectEqual(T{}, try parse(T, &ts, ParseOptions{})); |
| 2239 | 2239 | } |
| 2240 | 2240 | |
| 2241 | test "parse into struct where destination and source lengths mismatch" { | |
| 2242 | const T = struct { a: [2]u8 }; | |
| 2243 | var ts = TokenStream.init("{\"a\": \"bbb\"}"); | |
| 2244 | try testing.expectError(error.LengthMismatch, parse(T, &ts, ParseOptions{})); | |
| 2245 | } | |
| 2246 | ||
| 2241 | 2247 | test "parse into struct with misc fields" { |
| 2242 | 2248 | @setEvalBranchQuota(10000); |
| 2243 | 2249 | const options = ParseOptions{ .allocator = testing.allocator }; |