New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix StringMatchesFormatDescription with \r\n #3059
Conversation
This is a fix for sebastianbergmann#3040. There was a bug in that the following assertion would fail, even though it should pass: $this->assertStringMatchesFormat("\r\n", "\r\n"); Obviously, we would expect a string to match itself. The bug was due to newline conversion - `\r\n` was being converted to `\n` on the pattern, but not on the string to be matched against. In order to be compatible with existing behavior, we need to continue converting `\r\n` to `\n` in the pattern. (Otherwise, users who expect this behavior may have tests fail that would have previously passed.) Therefore, the only option for fixing the bug is to also sanitize the string to be matched. This commit makes that change, and provides some additional tests to verify the behavior.
Codecov Report
@@ Coverage Diff @@
## 7.0 #3059 +/- ##
============================================
+ Coverage 80.43% 80.45% +0.01%
- Complexity 2828 2830 +2
============================================
Files 107 107
Lines 7438 7443 +5
============================================
+ Hits 5983 5988 +5
Misses 1455 1455
Continue to review full report at Codecov.
|
As far as I see the changes, this would lead to: $this->assertStringMatchesFormat("\r\n", "\r\n"); // true
$this->assertStringMatchesFormat("\r", "\r\n"); // false
$this->assertStringMatchesFormat("\r\n", "\r"); // false
$this->assertStringMatchesFormat("\n", "\r\n"); // true
$this->assertStringMatchesFormat("\r\n", "\n"); // true Right? Not ideal, but better than before… |
That is correct. Perhaps it is worth some discussion whether this behavior should be changed or not:
|
How does the "official" PHPT test runner handle this? Because that is where this comes from. |
Huh, I didn't realize this was based on PHPT. I will see if I can do some experiments and report back in a few days. PHPT docs: https://qa.php.net/phpt_details.php#expectf_section |
https://github.com/php/php-src/blob/14de058086d76ac344fde67fc343023fc00279a9/run-tests.php#L2039 |
Merged manually, thanks. |
This is a proposed fix for #3040.
There was a bug in that the following assertion would fail, even though
it should pass:
Obviously, we would expect a string to match itself. The bug was due to
newline conversion -
\r\n
was being converted to\n
on the pattern,but not on the string to be matched against.
In order to be compatible with existing behavior, we need to continue
converting
\r\n
to\n
in the pattern. (Otherwise, users who expectthis behavior may have tests fail that would have previously passed.)
Therefore, the only option for fixing the bug is to also sanitize the
string to be matched. This commit makes that change, and provides some
additional tests to verify the behavior.