diff --git a/src/Matcher/JsonMatcher.php b/src/Matcher/JsonMatcher.php index 93267045..bdc937b1 100644 --- a/src/Matcher/JsonMatcher.php +++ b/src/Matcher/JsonMatcher.php @@ -31,8 +31,9 @@ public function match($value, $pattern) : bool return false; } - $transformedPattern = Json::transformPattern($pattern); + $transformedPattern = Json::isValid($pattern) ? $pattern : Json::transformPattern($pattern); $match = $this->matcher->match(\json_decode($value, true), \json_decode($transformedPattern, true)); + if (!$match) { $this->error = $this->matcher->getError(); return false; diff --git a/src/Matcher/Pattern/Assert/Json.php b/src/Matcher/Pattern/Assert/Json.php index 5df2c903..f9e814e4 100644 --- a/src/Matcher/Pattern/Assert/Json.php +++ b/src/Matcher/Pattern/Assert/Json.php @@ -28,7 +28,7 @@ public static function isValidPattern($value) : bool return false; } - return self::isValid(self::transformPattern($value)); + return self::isValid($value) || self::isValid(self::transformPattern($value)); } public static function transformPattern(string $pattern) : string diff --git a/tests/Matcher/JsonMatcherTest.php b/tests/Matcher/JsonMatcherTest.php index e4db2582..c3acd276 100644 --- a/tests/Matcher/JsonMatcherTest.php +++ b/tests/Matcher/JsonMatcherTest.php @@ -151,6 +151,7 @@ public static function positivePatterns() [\json_encode(['Norbert', 'MichaƂ'])], [\json_encode(['Norbert', '@string@'])], [\json_encode('test')], + [\json_encode(['foo' => '/foo/@uuid@/bar'])], ]; } diff --git a/tests/MatcherTest.php b/tests/MatcherTest.php index f80e8b78..28036739 100644 --- a/tests/MatcherTest.php +++ b/tests/MatcherTest.php @@ -131,6 +131,12 @@ public function jsonDataProvider() "nextPage": "@string@" }', ], + 'matches with txt matcher ' => [ + /** @lang JSON */ + '{"foo": "/foo/92ff9a6c-7fbd-47e5-b550-90b77e3284c7/bar"}', + /** @lang JSON */ + '{"foo": "/foo/@uuid@/bar"}' + ], 'matches json values with full text matcher' => [ /** @lang JSON */ '{