Skip to content

Commit b8ddc75

Browse files
authored
Fixed fail positive json detection (#210)
1 parent aaa3363 commit b8ddc75

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/Matcher/Pattern/Assert/Json.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ public static function isValid($value) : bool
1616
return false;
1717
}
1818

19-
if (null === \json_decode($value) && JSON_ERROR_NONE !== \json_last_error()) {
19+
$result = \json_decode($value);
20+
21+
if (\is_float($result) && \is_infinite($result)) {
22+
return false;
23+
}
24+
25+
if (null === $result && JSON_ERROR_NONE !== \json_last_error()) {
2026
return false;
2127
}
2228

tests/Matcher/JsonMatcherTest.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,11 @@ public static function positiveMatches()
244244
[
245245
'[{"name": "Norbert"},{"name":"Michał"},{"name":"Bob"},{"name":"Martin"}]',
246246
'"@[email protected]({\"name\": \"@string@\"})"'
247-
]
247+
],
248+
[
249+
'{"something": "5e61188283825"}',
250+
'{"something": "@string@"}',
251+
],
248252
];
249253
}
250254

0 commit comments

Comments
 (0)