Skip to content

Commit

Permalink
Check for \r as newline in closing tag
Browse files Browse the repository at this point in the history
Fixes #761.
  • Loading branch information
nikic committed Apr 25, 2021
1 parent 8eb194e commit 4848a0d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion lib/PhpParser/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,8 @@ public function getNextToken(&$value = null, &$startAttributes = null, &$endAttr
$value = $token[1];
$id = $this->tokenMap[$token[0]];
if (\T_CLOSE_TAG === $token[0]) {
$this->prevCloseTagHasNewline = false !== strpos($token[1], "\n");
$this->prevCloseTagHasNewline = false !== strpos($token[1], "\n")
|| false !== strpos($token[1], "\r");
} elseif (\T_INLINE_HTML === $token[0]) {
$startAttributes['hasLeadingNewline'] = $this->prevCloseTagHasNewline;
}
Expand Down
11 changes: 10 additions & 1 deletion test/code/prettyPrinter/inlineHTMLandPHPtest.file-test
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,13 @@ HTML<?php echo 'PHP'; ?>HTML
-----
HTML<?php
echo 'PHP';
?>HTML
?>HTML
-----
<?php
echo 'PHP';
?>@@{ "\r\r\n" }@@Test
-----
<?php

echo 'PHP';
?>@@{ "\n\n" }@@Test

0 comments on commit 4848a0d

Please sign in to comment.