Skip to content

Commit 72dbafd

Browse files
committed
Assert: fixed NUL byte escaping in match()
1 parent 7700c4d commit 72dbafd

File tree

2 files changed

+4
-2
lines changed

2 files changed

+4
-2
lines changed

src/Framework/Assert.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,8 @@ public static function isMatching($pattern, $actual, $strict = FALSE)
495495
$utf8 = preg_match('#\x80-\x{10FFFF}]#u', $pattern) ? 'u' : '';
496496
$suffix = ($strict ? '\z#sU' : '\s*$#sU') . $utf8;
497497
$patterns = static::$patterns + [
498-
'[.\\\\+*?[^$(){|\x00\#]' => '\$0', // preg quoting
498+
'[.\\\\+*?[^$(){|\#]' => '\$0', // preg quoting
499+
'\x00' => '\x00',
499500
'[\t ]*\r?\n' => '[\t ]*\r?\n', // right trim
500501
];
501502
$pattern = '#^' . preg_replace_callback('#' . implode('|', array_keys($patterns)) . '#U' . $utf8, function ($m) use ($patterns) {
@@ -505,7 +506,7 @@ public static function isMatching($pattern, $actual, $strict = FALSE)
505506
return $s;
506507
}
507508
}
508-
}, rtrim($pattern)) . $suffix;
509+
}, rtrim($pattern, " \t\n\r")) . $suffix;
509510
}
510511

511512
$res = preg_match($pattern, $actual);

tests/Framework/Assert.match.phpt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ $matches = [
1414
["a\nb", "a\t \nb"],
1515
["a\t\r\n\t ", 'a'],
1616
['a', "a\t\r\n\t "],
17+
["\x00", "\x00"],
1718
['%%', '%'],
1819
['%%a%%', '%a%'],
1920
['%a%', 'a b'],

0 commit comments

Comments
 (0)