File tree 2 files changed +15
-2
lines changed
2 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -530,9 +530,21 @@ public static function regexify($regex = '')
530
530
// replace \d with number and \w with letter and . with ascii
531
531
$ regex = preg_replace_callback ('/ \\\w/ ' , 'static::randomLetter ' , $ regex );
532
532
$ regex = preg_replace_callback ('/ \\\d/ ' , 'static::randomDigit ' , $ regex );
533
- $ regex = preg_replace_callback ('/(?<! \\\)\./ ' , 'static::randomAscii ' , $ regex );
534
- // remove remaining backslashes
533
+ //replace . with ascii except backslash
534
+ $ regex = preg_replace_callback ('/(?<! \\\)\./ ' , static function () {
535
+ $ chr = static ::asciify ('* ' );
536
+
537
+ if ($ chr === '\\' ) {
538
+ $ chr .= '\\' ;
539
+ }
540
+
541
+ return $ chr ;
542
+ }, $ regex );
543
+ // remove remaining single backslashes
544
+ $ regex = str_replace ('\\\\' , '[:escaped_backslash:] ' , $ regex );
535
545
$ regex = str_replace ('\\' , '' , $ regex );
546
+ $ regex = str_replace ('[:escaped_backslash:] ' , '\\' , $ regex );
547
+
536
548
// phew
537
549
return $ regex ;
538
550
}
Original file line number Diff line number Diff line change @@ -339,6 +339,7 @@ public function regexifyDataProvider()
339
339
['\.\*\?\+ ' , 'escaped characters ' ],
340
340
['[.] ' , 'literal dot in character class ' ],
341
341
['. ' , 'catch-all dot ' ],
342
+ ['\\\\' , 'escaped backslash ' ],
342
343
['[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4} ' , 'complex regex ' ],
343
344
];
344
345
}
You can’t perform that action at this time.
0 commit comments