Skip to content

Commit 6593e66

Browse files
committed
minor #4699 LineEndingFixer - handle "\r\r\n" (kubawerlos)
This PR was squashed before being merged into the 2.15 branch (closes #4699). Discussion ---------- LineEndingFixer - handle "\r\r\n" The added test is converting the input to expected, but it fails because: > Code build on input code must match expected code. We have two ways to fix it: 1. Update the RegEx `#\r\n|\n#` to `#\r+\n|\n#` 2. Update the RegEx `#\r\n|\n#` to `#\r\n|\r|\n#` and test case to: ```php $cases[] = [ "<?php echo 'foo',\n\n'bar';", "<?php echo 'foo',\r\r\n'bar';", ]; ``` Option 2 seems more right as the original `\r\r\n` is treated (at least in PHPStorm) as 2 line endings. Ping @fabpot, @SpacePossum and @keradus as authors for opinion. Commits ------- b465a72 LineEndingFixer - handle \"\r\r\n\"
2 parents 289d853 + b465a72 commit 6593e66

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

src/Fixer/Whitespace/LineEndingFixer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
6767
$tokens[$index] = new Token([
6868
$token->getId(),
6969
Preg::replace(
70-
"#\r\n|\n#",
70+
'#\R#',
7171
$ending,
7272
$token->getContent()
7373
),
@@ -81,7 +81,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens)
8181
$tokens[$index] = new Token([
8282
$token->getId(),
8383
Preg::replace(
84-
"#\r\n|\n#",
84+
'#\R#',
8585
$ending,
8686
$token->getContent()
8787
),

tests/Fixer/Whitespace/LineEndingFixerTest.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ public function provideFixCases()
6060
"<?php \$a=\"a\r\n\";",
6161
];
6262

63+
$cases[] = [
64+
"<?php echo 'foo',\n\n'bar';",
65+
"<?php echo 'foo',\r\r\n'bar';",
66+
];
67+
6368
return $cases;
6469
}
6570

0 commit comments

Comments
 (0)