Skip to content

Commit 20e6e25

Browse files
author
ellisgl
committed
ISSUE-5320 Extended for special matching delimiters.
1 parent 9d67af7 commit 20e6e25

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

src/Codeception/Util/JsonType.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,10 @@ protected function typeComparison($data, $jsonType)
130130
continue;
131131
}
132132

133-
$regexMatcher = '/:regex\(((.).*?\2)\)/';
133+
$regexMatcher = '/:regex\((((\()|(\{)|(\[)|(<)|(.)).*?(?(3)\)|(?(4)\}|(?(5)\]|(?(6)>|\7)))))\)/';
134134
$regexes = [];
135135

136-
// Match the string ':regex(' and any characters until a regex delimiter (matches 99.999% use cases) followed by character ')'
136+
// Match the string ':regex(' and any characters until a ending regex delimiter followed by character ')'
137137
// Place the 'any character' + delimiter matches in to an array.
138138
preg_match_all($regexMatcher, $type, $regexes);
139139

tests/unit/Codeception/Util/JsonTypeTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,4 +239,14 @@ public function testRegexFilterWithPostfixedAlternatives()
239239
// currently produces a false negative
240240
$this->assertTrue($jsonType->matches(['test' => 'string:regex(~^(\d\d@):\d\d$~)|integer']));
241241
}
242+
243+
public function testRegexFilterWithSpecialDelimiters()
244+
{
245+
$jsonType = new JsonType(['test' => 'xyz']);
246+
247+
$this->assertTrue($jsonType->matches(['test' => 'string:regex([xyz])']));
248+
$this->assertTrue($jsonType->matches(['test' => 'string:regex({xyz})']));
249+
$this->assertTrue($jsonType->matches(['test' => 'string:regex(<xyz>)']));
250+
$this->assertTrue($jsonType->matches(['test' => 'string:regex((xyz))']));
251+
}
242252
}

0 commit comments

Comments
 (0)