Skip to content

Commit fcff418

Browse files
committed
Merge branch 'PHP-7.4'
* PHP-7.4: Fix #79934: CRLF-only line in heredoc causes parsing error
2 parents 84a080e + 2cbc940 commit fcff418

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

Zend/tests/bug79934.phpt

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
Bug #79934: CRLF-only line in heredoc causes parsing error
3+
--DESCRIPTION--
4+
This test covers different variations of whitespace-only lines in heredoc strings.
5+
These whitespace-only lines should be ignored when stripping indentation.
6+
--FILE--
7+
<?php
8+
// lines with only CRLF should not cause a parse error
9+
eval("\$s1 = <<<HEREDOC\r\n a\r\n\r\n b\r\n HEREDOC;");
10+
var_dump(addcslashes($s1, "\r\n"));
11+
12+
// lines with only a LF should not cause a parse error
13+
eval("\$s2 = <<<HEREDOC\n a\n\n b\n HEREDOC;");
14+
var_dump(addcslashes($s2, "\n"));
15+
16+
// lines with only a CR should not cause a parse error
17+
eval("\$s3 = <<<HEREDOC\r a\r\r b\r HEREDOC;");
18+
var_dump(addcslashes($s3, "\r"));
19+
20+
// lines with only whitespace should not cause a parse error
21+
eval("\$s4 = <<<HEREDOC\r a\r\n \r\n b\r HEREDOC;");
22+
var_dump(addcslashes($s4, "\n\r"));
23+
24+
?>
25+
--EXPECT--
26+
string(10) "a\r\n\r\nb"
27+
string(6) "a\n\nb"
28+
string(6) "a\r\rb"
29+
string(10) "a\r\n\r\nb"

Zend/zend_language_scanner.l

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1170,6 +1170,7 @@ static const char *next_newline(const char *str, const char *end, size_t *newlin
11701170
for (; str < end; str++) {
11711171
if (*str == '\r') {
11721172
*newline_len = str + 1 < end && *(str + 1) == '\n' ? 2 : 1;
1173+
return str;
11731174
} else if (*str == '\n') {
11741175
*newline_len = 1;
11751176
return str;

0 commit comments

Comments
 (0)