This PR fix std.json to honor max_value_len for sentinel-terminated strings and add a regression test.
Fixes #30579
reproduction (before this commit)
❯ zig version
0.16.0-dev.2040+c475f1fcd
❯ zig test sandbox/repro-30579.zig
1/1 repro-30579.test.max_value_len greater than default_max_value_len...FAIL (ValueTooLong)
not commited (snippet just for reproduction) sandbox/repro-30579.zig
const std = @import("std");
const testing = std.testing;
test "max_value_len greater than default_max_value_len" {
const allocator = testing.allocator;
const json_string =
"\"" ++ "a" ** (std.json.default_max_value_len + 1) ++ "\"";
const res = try std.json.parseFromSlice(
[:0]const u8,
allocator,
json_string,
.{ .max_value_len = std.json.default_max_value_len + 1 },
);
defer res.deinit();
try testing.expectEqual(res.value.len, std.json.default_max_value_len + 1);
}
verification (after this commit)
❯ mkdir build
❯ cd build
❯ cmake ..
❯ make install
❯ cd ..
❯ ./build/stage3/bin/zig test sandbox/repro-30579.zig
All 1 tests passed.
This PR fix `std.json` to honor `max_value_len` for sentinel-terminated strings and add a regression test.
Fixes https://codeberg.org/ziglang/zig/issues/30579
reproduction (before this commit)
```
❯ zig version
0.16.0-dev.2040+c475f1fcd
❯ zig test sandbox/repro-30579.zig
1/1 repro-30579.test.max_value_len greater than default_max_value_len...FAIL (ValueTooLong)
```
not commited (snippet just for reproduction) `sandbox/repro-30579.zig`
```
const std = @import("std");
const testing = std.testing;
test "max_value_len greater than default_max_value_len" {
const allocator = testing.allocator;
const json_string =
"\"" ++ "a" ** (std.json.default_max_value_len + 1) ++ "\"";
const res = try std.json.parseFromSlice(
[:0]const u8,
allocator,
json_string,
.{ .max_value_len = std.json.default_max_value_len + 1 },
);
defer res.deinit();
try testing.expectEqual(res.value.len, std.json.default_max_value_len + 1);
}
```
verification (after this commit)
```
❯ mkdir build
❯ cd build
❯ cmake ..
❯ make install
❯ cd ..
❯ ./build/stage3/bin/zig test sandbox/repro-30579.zig
All 1 tests passed.
```