Skip to content

Commit

Permalink
Fixed fail positive json detection (#210)
Browse files Browse the repository at this point in the history
  • Loading branch information
norberttech authored Sep 27, 2020
1 parent aaa3363 commit b8ddc75
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/Matcher/Pattern/Assert/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ public static function isValid($value) : bool
return false;
}

if (null === \json_decode($value) && JSON_ERROR_NONE !== \json_last_error()) {
$result = \json_decode($value);

if (\is_float($result) && \is_infinite($result)) {
return false;
}

if (null === $result && JSON_ERROR_NONE !== \json_last_error()) {
return false;
}

Expand Down
6 changes: 5 additions & 1 deletion tests/Matcher/JsonMatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,11 @@ public static function positiveMatches()
[
'[{"name": "Norbert"},{"name":"Michał"},{"name":"Bob"},{"name":"Martin"}]',
'"@[email protected]({\"name\": \"@string@\"})"'
]
],
[
'{"something": "5e61188283825"}',
'{"something": "@string@"}',
],
];
}

Expand Down

0 comments on commit b8ddc75

Please sign in to comment.