Skip to content

Commit 2cbc940

Browse files
committed
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3: Fix #79934: CRLF-only line in heredoc causes parsing error
2 parents 99645f5 + 06ade15 commit 2cbc940

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ PHP NEWS
99
. Fixed bug #79895 (PHP_CHECK_GCC_ARG does not allow flags with equal sign).
1010
(Santiago M. Mola)
1111
. Fixed bug #79919 (Stack use-after-scope in define()). (cmb)
12+
. Fixed bug #79934 (CRLF-only line in heredoc causes parsing error).
13+
(Pieter van den Ham)
1214

1315
- LDAP:
1416
. Fixed memory leaks. (ptomulik)

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
@@ -1118,6 +1118,7 @@ static const char *next_newline(const char *str, const char *end, size_t *newlin
11181118
for (; str < end; str++) {
11191119
if (*str == '\r') {
11201120
*newline_len = str + 1 < end && *(str + 1) == '\n' ? 2 : 1;
1121+
return str;
11211122
} else if (*str == '\n') {
11221123
*newline_len = 1;
11231124
return str;

0 commit comments

Comments
 (0)