File tree Expand file tree Collapse file tree 2 files changed +24
-1
lines changed
tests/unit/Codeception/Util Expand file tree Collapse file tree 2 files changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -130,7 +130,7 @@ protected function typeComparison($data, $jsonType)
130130 continue ;
131131 }
132132
133- $ regexMatcher = '/:regex\((.*?)\)(?:\|(boolean|integer|double|float|string|array|object|resource|resource \(closed\)|null|unknown type)|$ )/ ' ;
133+ $ regexMatcher = '/:regex\(((.).*?\2)\ )/ ' ;
134134 $ regexes = [];
135135
136136 // Match the string ':regex(' and any characters until a regex delimiter (matches 99.999% use cases) followed by character ')'
Original file line number Diff line number Diff line change @@ -216,4 +216,27 @@ public function testMatchesArrayReturnedByFetchBoth()
216216 'b ' => 'integer ' ,
217217 ]));
218218 }
219+
220+ public function testRegexFilterWithPrefixedAlternatives ()
221+ {
222+ $ jsonType = new JsonType (['test ' => null ]);
223+ $ this ->assertTrue ($ jsonType ->matches (['test ' => 'null|string:regex(~^(\d\d@):\d\d$~) ' ]));
224+ $ this ->assertNotTrue ($ jsonType ->matches (['test ' => 'integer|string:regex(~^(\d\d@):\d\d$~) ' ]));
225+
226+ $ jsonType = new JsonType (['test ' => 12345 ]);
227+ $ this ->assertTrue ($ jsonType ->matches (['test ' => 'integer|null|string:regex(~^(\d\d@):\d\d$~) ' ]));
228+ }
229+
230+ public function testRegexFilterWithPostfixedAlternatives ()
231+ {
232+ $ jsonType = new JsonType (['test ' => null ]);
233+ // currently produces a false positive
234+ $ this ->assertNotTrue ($ jsonType ->matches (['test ' => 'string:regex(~^(\d\d@):\d\d$~)|integer ' ]));
235+ // currently produces a false negative
236+ $ this ->assertTrue ($ jsonType ->matches (['test ' => 'string:regex(~^(\d\d@):\d\d$~)|null ' ]));
237+
238+ $ jsonType = new JsonType (['test ' => 12345 ]);
239+ // currently produces a false negative
240+ $ this ->assertTrue ($ jsonType ->matches (['test ' => 'string:regex(~^(\d\d@):\d\d$~)|integer ' ]));
241+ }
219242}
You can’t perform that action at this time.
0 commit comments