]> granicus.if.org Git - php/commitdiff
Fix heredoc handling. (Patch by Matt Wilmas)
authorScott MacVicar <scottmac@php.net>
Wed, 9 Apr 2008 21:40:13 +0000 (21:40 +0000)
committerScott MacVicar <scottmac@php.net>
Wed, 9 Apr 2008 21:40:13 +0000 (21:40 +0000)
NEWS
Zend/zend_language_scanner.l

diff --git a/NEWS b/NEWS
index 091a86c22d1bd9865a53df9f32ecad9621ed40a7..b633ae64c7caf3e77d07cd46ab1fcb43e50319ad 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,8 @@
 PHP                                                                        NEWS
 |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
 ?? Apr 2008, PHP 5.2.6
+- Fixed incorrect heredoc handling when label is used within the block.
+  (Matt Wilmas)
 - Fixed bug #44673 (With CGI argv/argc starts from arguments, not from script)
   (Dmitry)
 - Fixed bug #44667 (proc_open() does not handle pipes with the mode 'wb'
index a8ee9e796e1b8744efada42d59392beecba618e9..8356408b129847ec8ae3835dae620c8a209a9e02 100644 (file)
@@ -1919,8 +1919,13 @@ HEREDOC_CHARS       ("{"*([^$\n\r\\{]|("\\"[^\n\r]))|{HEREDOC_LITERAL_DOLLAR}|({
        if (yyleng > CG(heredoc_len) && !memcmp(end - CG(heredoc_len), CG(heredoc), CG(heredoc_len))) {
                int len = yyleng - CG(heredoc_len) - 2; /* 2 for newline before and after label */
 
-               if (len > 0 && yytext[len - 1] == '\r' && yytext[len] == '\n') {
-                       len--;
+               /* May have matched fooLABEL; make sure there's a newline before it */
+               if (yytext[len] != '\n') {
+                       if (yytext[len] != '\r') {
+                               goto wrong_label;
+                       }
+               } else if (len > 0 && yytext[len - 1] == '\r') {
+                       len--; /* Windows newline */
                }
 
                /* Go back before last label char, to match in ST_END_HEREDOC state */
@@ -1937,6 +1942,7 @@ HEREDOC_CHARS       ("{"*([^$\n\r\\{]|("\\"[^\n\r]))|{HEREDOC_LITERAL_DOLLAR}|({
        } else {
                /* Go back to end of label, so the next match works correctly in case of
                 * a variable or another label at the beginning of the next line */
+wrong_label:
                yyless(yyleng - 1);
                yymore();
        }