Skip to content

Commit

Permalink
NonPrintableCharacterFixer - fix for string in single quotes, having …
Browse files Browse the repository at this point in the history
…non-breaking space, linebreak, and single quote inside
  • Loading branch information
kubawerlos authored and SpacePossum committed Dec 14, 2021
1 parent 2c944f8 commit c02a447
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Fixer/Basic/NonPrintableCharacterFixer.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens): void

if ($swapQuotes) {
$content = str_replace('"', '\"', $content);
$content = Preg::replace('/^\'(.*)\'$/', '"$1"', $content);
$content = Preg::replace('/^\'(.*)\'$/s', '"$1"', $content);
}

$tokens[$index] = new Token([$token->getId(), strtr($content, $escapeSequences)]);
Expand Down
4 changes: 4 additions & 0 deletions tests/Fixer/Basic/NonPrintableCharacterFixerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,10 @@ function f(string $p)
INPUT
, pack('H*', 'e2808b')),
],
[
"<?php \"String in single quotes, having non-breaking space: \\u{a0}, linebreak: \n, and single quote inside: ' is a dangerous mix.\";",
"<?php 'String in single quotes, having non-breaking space: ".pack('H*', 'c2a0').", linebreak: \n, and single quote inside: \\' is a dangerous mix.';",
],
];
}
}

0 comments on commit c02a447

Please sign in to comment.