Skip to content

Commit 06ade15

Browse files
pevdhnikic
authored andcommitted
Fix #79934: CRLF-only line in heredoc causes parsing error
Fixes the function `next_newline()` in zend_language_scanner.l. The function now correctly returns a newline_len of 2 for "\r\n". Closes GH-5944.
1 parent 6a1bd57 commit 06ade15

File tree

5 files changed

+383
-351
lines changed

5 files changed

+383
-351
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"

0 commit comments

Comments
 (0)