File tree 2 files changed +4
-1
lines changed
2 files changed +4
-1
lines changed Original file line number Diff line number Diff line change @@ -525,7 +525,9 @@ public static function regexify($regex = '')
525
525
}, $ regex );
526
526
// All [ABC] become B (or A or C)
527
527
$ regex = preg_replace_callback ('/\[([^\]]+)\]/ ' , static function ($ matches ) {
528
- $ randomElement = Base::randomElement (str_split ($ matches [1 ]));
528
+ // remove backslashes (that are not followed by another backslash) because they are escape characters
529
+ $ match = preg_replace ('/ \\\(?! \\\)/ ' , '' , $ matches [1 ]);
530
+ $ randomElement = Base::randomElement (str_split ($ match ));
529
531
//[.] should not be a random character, but a literal .
530
532
return str_replace ('. ' , '\. ' , $ randomElement );
531
533
}, $ regex );
Original file line number Diff line number Diff line change @@ -333,6 +333,7 @@ public function regexifyDataProvider()
333
333
['[aeiou] ' , 'basic character class ' ],
334
334
['[a-z] ' , 'character class range ' ],
335
335
['[a-z1-9] ' , 'multiple character class range ' ],
336
+ ['[a-z\-]{4} ' , 'character class range with quantifier and escaped character ' ],
336
337
['a*b+c? ' , 'single character quantifiers ' ],
337
338
['a{2} ' , 'brackets quantifiers ' ],
338
339
['a{2,3} ' , 'min-max brackets quantifiers ' ],
You can’t perform that action at this time.
0 commit comments