Skip to content

Commit 859ac4f

Browse files
Emix33nicolas-grekas
authored andcommitted
Fix json_validate rejecting valid maximum depth
1 parent 6bbe0d5 commit 859ac4f

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

src/Php83/Php83.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static function json_validate(string $json, int $depth = 512, int $flags
3030
throw new \ValueError('json_validate(): Argument #2 ($depth) must be greater than 0');
3131
}
3232

33-
if ($depth >= self::JSON_MAX_DEPTH) {
33+
if ($depth > self::JSON_MAX_DEPTH) {
3434
throw new \ValueError(sprintf('json_validate(): Argument #2 ($depth) must be less than %d', self::JSON_MAX_DEPTH));
3535
}
3636

tests/Php83/Php83Test.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public static function jsonDataProvider(): iterable
4646
yield [true, '{ "test": {"foo": "bar"}, "test2": {"foo" : "bar" }, "test3": {"foo" : "bar" } }'];
4747
yield [false, '{"key1":"value1", "key2":"value2"}', 'Maximum stack depth exceeded', 1];
4848
yield [false, "\"a\xb0b\"", 'Malformed UTF-8 characters, possibly incorrectly encoded'];
49+
yield [true, '{ "test": { "foo": "bar" } }', 'No error', 2147483647];
4950

5051
if (\defined('JSON_INVALID_UTF8_IGNORE')) {
5152
yield [true, "\"a\xb0b\"", 'No error', 512, \JSON_INVALID_UTF8_IGNORE];
@@ -73,8 +74,9 @@ public function testInvalidOptionsProvided(int $depth, int $flags, string $expec
7374
public static function invalidOptionsProvider(): iterable
7475
{
7576
yield [0, 0, 'json_validate(): Argument #2 ($depth) must be greater than 0'];
76-
yield [\PHP_INT_MAX, 0, 'json_validate(): Argument #2 ($depth) must be less than 2147483647'];
77-
77+
if (\PHP_INT_MAX > 2147483647) {
78+
yield [\PHP_INT_MAX, 0, 'json_validate(): Argument #2 ($depth) must be less than 2147483647'];
79+
}
7880
if (\defined('JSON_INVALID_UTF8_IGNORE')) {
7981
yield [
8082
512,

0 commit comments

Comments
 (0)