Strip trailing doc string newline before parsing escape sequences

If the doc string ends on an escaped \r, it should not get eaten
as the "last newline".
This commit is contained in:
Nikita Popov 2023-03-01 21:05:55 +01:00
parent 4c3e759a51
commit c62dda9507
2 changed files with 17 additions and 1 deletions

View File

@ -823,10 +823,10 @@ abstract class ParserAbstract implements Parser {
$part->value, $indentLen, $indentChar,
$i === 0, $isLast, $part->getAttributes()
);
$part->value = String_::parseEscapeSequences($part->value, null, $parseUnicodeEscape);
if ($isLast) {
$part->value = preg_replace('~(\r\n|\n|\r)\z~', '', $part->value);
}
$part->value = String_::parseEscapeSequences($part->value, null, $parseUnicodeEscape);
if ('' === $part->value) {
continue;
}

View File

@ -28,6 +28,10 @@ b<<<EOS
Binary
EOS;
<<<EOS
$x\r
EOS;
-----
array(
0: Stmt_Expression(
@ -112,4 +116,16 @@ array(
value: Binary
)
)
7: Stmt_Expression(
expr: Scalar_InterpolatedString(
parts: array(
0: Expr_Variable(
name: x
)
1: InterpolatedStringPart(
value:
)
)
)
)
)