From d7d13a5d8516c94116c6d6da3b7ffaf5396d3d0c Mon Sep 17 00:00:00 2001 From: Norbert Orzechowicz Date: Sun, 27 Sep 2020 10:50:10 +0200 Subject: [PATCH] Fixed issue with false positive detection of valid json string (#209) * Fixed false positive detection of valid json strings * CS Fixes * Added phive install step to github workflows --- .github/workflows/mutation.yml | 4 ++++ .github/workflows/static-analyze.yml | 5 ++++- .github/workflows/tests.yml | 5 ++++- src/Matcher/Pattern/Assert/Json.php | 8 +++++++- tests/Matcher/JsonMatcherTest.php | 4 ++++ 5 files changed, 23 insertions(+), 3 deletions(-) diff --git a/.github/workflows/mutation.yml b/.github/workflows/mutation.yml index 8c3d68f6..cbf8011e 100644 --- a/.github/workflows/mutation.yml +++ b/.github/workflows/mutation.yml @@ -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: diff --git a/.github/workflows/static-analyze.yml b/.github/workflows/static-analyze.yml index e642656c..8b4a08e8 100644 --- a/.github/workflows/static-analyze.yml +++ b/.github/workflows/static-analyze.yml @@ -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' }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a746a43a..b1313f13 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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' }} diff --git a/src/Matcher/Pattern/Assert/Json.php b/src/Matcher/Pattern/Assert/Json.php index aa9f391e..d1b5797d 100644 --- a/src/Matcher/Pattern/Assert/Json.php +++ b/src/Matcher/Pattern/Assert/Json.php @@ -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; } diff --git a/tests/Matcher/JsonMatcherTest.php b/tests/Matcher/JsonMatcherTest.php index 6fbce914..e63424b0 100644 --- a/tests/Matcher/JsonMatcherTest.php +++ b/tests/Matcher/JsonMatcherTest.php @@ -111,6 +111,10 @@ public static function positiveMatches() '[{"name": "Norbert"},{"name":"MichaƂ"},{"name":"Bob"},{"name":"Martin"}]', '"@array@.repeat({\"name\": \"@string@\"})"', ], + [ + '{"something": "5e61188283825"}', + '{"something": "@string@"}', + ], ]; }