Skip to content

Commit

Permalink
Fixed issue with false positive detection of valid json string (#209)
Browse files Browse the repository at this point in the history
* Fixed false positive detection of valid json strings

* CS Fixes

* Added phive install step to github workflows
  • Loading branch information
norberttech authored Sep 27, 2020
1 parent 48f1767 commit d7d13a5
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 3 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/mutation.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,13 @@ jobs:
uses: "shivammathur/setup-php@v2"
with:
coverage: "pcov"
tools: phive, composer:v2
php-version: "${{ matrix.php-version }}"
ini-values: memory_limit=-1

- name: "Install tools"
run: "phive install --trust-gpg-keys E82B2FB314E9906E,CF1A108D0E7AE720,8A03EA3B385DBAA1,C5095986493B4AA0 --force-accept-unsigned"

- name: "Cache dependencies"
uses: "actions/cache@v2"
with:
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/static-analyze.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ jobs:
coverage: "pcov"
php-version: "${{ matrix.php-version }}"
ini-values: memory_limit=-1
tools: composer:v2
tools: phive, composer:v2

- name: "Install tools"
run: "phive install --trust-gpg-keys E82B2FB314E9906E,CF1A108D0E7AE720,8A03EA3B385DBAA1,C5095986493B4AA0 --force-accept-unsigned"

- name: "Install lowest dependencies"
if: ${{ matrix.dependencies == 'lowest' }}
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ jobs:
coverage: "pcov"
php-version: "${{ matrix.php-version }}"
ini-values: memory_limit=-1
tools: composer:v2
tools: phive, composer:v2

- name: "Install tools"
run: "phive install --trust-gpg-keys E82B2FB314E9906E,CF1A108D0E7AE720,8A03EA3B385DBAA1,C5095986493B4AA0 --force-accept-unsigned"

- name: "Install lowest dependencies"
if: ${{ matrix.dependencies == 'lowest' }}
Expand Down
8 changes: 7 additions & 1 deletion src/Matcher/Pattern/Assert/Json.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,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
4 changes: 4 additions & 0 deletions tests/Matcher/JsonMatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ 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 d7d13a5

Please sign in to comment.