From 7b7ecdefc7f0507bfafc520efbeaf7e10410a4b7 Mon Sep 17 00:00:00 2001 From: Jan Tvrdik Date: Thu, 19 May 2016 20:20:52 +0200 Subject: [PATCH] Assert: match() minor refactoring of whitespace normalization --- src/Framework/Assert.php | 3 +-- tests/Framework/Assert.match.phpt | 8 ++++++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/Framework/Assert.php b/src/Framework/Assert.php index 99e0ee1a..912afa39 100644 --- a/src/Framework/Assert.php +++ b/src/Framework/Assert.php @@ -486,7 +486,7 @@ public static function isMatching($pattern, $actual) $utf8 = preg_match('#\x80-\x{10FFFF}]#u', $pattern) ? 'u' : ''; $patterns = static::$patterns + [ '[.\\\\+*?[^$(){|\x00\#]' => '\$0', // preg quoting - '[\t ]*\r?\n' => "[\\t ]*\n", // right trim + '[\t ]*\r?\n' => '[\t ]*\r?\n', // right trim ]; $pattern = '#^' . preg_replace_callback('#' . implode('|', array_keys($patterns)) . '#U' . $utf8, function ($m) use ($patterns) { foreach ($patterns as $re => $replacement) { @@ -496,7 +496,6 @@ public static function isMatching($pattern, $actual) } } }, rtrim($pattern)) . '\s*$#sU' . $utf8; - $actual = str_replace("\r\n", "\n", $actual); } $res = preg_match($pattern, $actual); diff --git a/tests/Framework/Assert.match.phpt b/tests/Framework/Assert.match.phpt index 42140064..b6abd86b 100644 --- a/tests/Framework/Assert.match.phpt +++ b/tests/Framework/Assert.match.phpt @@ -8,8 +8,12 @@ require __DIR__ . '/../bootstrap.php'; $matches = [ ['1', '1'], ['1', 1], - ['a', "a \t\r\n\t \n"], - ["a \t\r\n", 'a'], + ["a\nb", "a\r\nb"], + ["a\r\nb", "a\nb"], + ["a\t \nb", "a\nb"], + ["a\nb", "a\t \nb"], + ["a\t\r\n\t ", 'a'], + ['a', "a\t\r\n\t "], ['%a%', 'a b'], ['%a?%', 'a b'], ['%a?%', ''],