]> granicus.if.org Git - php/commitdiff
Fixed bug #35655 (whitespace following end of heredoc is lost).
authorIlia Alshanetsky <iliaa@php.net>
Tue, 13 Dec 2005 20:55:42 +0000 (20:55 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Tue, 13 Dec 2005 20:55:42 +0000 (20:55 +0000)
NEWS
Zend/tests/bug35655.phpt [new file with mode: 0755]
Zend/zend_highlight.c
Zend/zend_language_scanner.l
ext/tokenizer/tests/bug26463.phpt

diff --git a/NEWS b/NEWS
index 61745e176e8e5e64479b98af7fb6024f40c87967..8e5f792988f09b94d9cf2e8d8feca9830092d49b 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -26,6 +26,7 @@ PHP                                                                        NEWS
 - Fixed many bugs in OCI8. (Tony)
 - Fixed crash and leak in mysqli when using 4.1.x client libraries and
   connecting to 5.x server. (Andrey)
+- Fixed bug #35655 (whitespace following end of heredoc is lost). (Ilia)
 - Fixed bug #35630 (strtotime() crashes on certain relative identifiers).
   (Ilia)
 - Fixed bug #35629 (crash in http:// wrapper on multiple redirects). (Ilia)
diff --git a/Zend/tests/bug35655.phpt b/Zend/tests/bug35655.phpt
new file mode 100755 (executable)
index 0000000..30f00cb
--- /dev/null
@@ -0,0 +1,18 @@
+--TEST--
+Bug #35655 (whitespace following end of heredoc is lost)
+--FILE--
+<?php
+$code = '
+<? 
+  $x = <<<EOT
+some string    
+EOT
+  $y = 2;
+?>';
+highlight_string($code);
+?>
+--EXPECT--
+<code><span style="color: #000000">
+<br /><span style="color: #0000BB">&lt;?&nbsp;<br />&nbsp;&nbsp;$x&nbsp;</span><span style="color: #007700">=&nbsp;&lt;&lt;&lt;EOT<br /></span><span style="color: #0000BB">some&nbsp;string&nbsp;&nbsp;&nbsp;&nbsp;<br /></span><span style="color: #007700">EOT<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$y&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">2</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">?&gt;</span>
+</span>
+</code>
index d32b79c7b5cc0a2406dbf7a837d237834a84a183..a6151717d0b4c6f48879a2a5d97bf57a55fe0f93 100644 (file)
@@ -94,7 +94,7 @@ ZEND_API void zend_highlight(zend_syntax_highlighter_ini *syntax_highlighter_ini
        int token_type;
        char *last_color = syntax_highlighter_ini->highlight_html;
        char *next_color;
-       int in_string=0, post_heredoc = 0;
+       int in_string=0;
 
        zend_printf("<code>");
        zend_printf("<span style=\"color: %s\">\n", last_color);
@@ -151,14 +151,9 @@ ZEND_API void zend_highlight(zend_syntax_highlighter_ini *syntax_highlighter_ini
                switch (token_type) {
                        case T_END_HEREDOC:
                                zend_html_puts(token.value.str.val, token.value.str.len TSRMLS_CC);
-                               post_heredoc = 1;
                                break;
                        default:
                                zend_html_puts(LANG_SCNG(yy_text), LANG_SCNG(yy_leng) TSRMLS_CC);
-                               if (post_heredoc) {
-                                        zend_html_putc('\n');
-                                        post_heredoc = 0;
-                               }
                                break;
                }
 
@@ -215,19 +210,18 @@ ZEND_API void zend_strip(TSRMLS_D)
                        case EOF:
                                return;
                        
-                       case T_END_HEREDOC: {
-                                       char *ptr = LANG_SCNG(yy_text);
-
-                                       zend_write(ptr, LANG_SCNG(yy_leng) - 1);
-                                       /* The ensure that we only write one ; and that it followed by the required newline */
-                                       zend_write("\n", sizeof("\n") - 1);
-                                       if (ptr[LANG_SCNG(yy_leng) - 1] == ';') {
-                                               lex_scan(&token TSRMLS_CC);
-                                       }
-                                       efree(token.value.str.val);
+                       case T_END_HEREDOC:
+                               zend_write(LANG_SCNG(yy_text), LANG_SCNG(yy_leng));
+                               efree(token.value.str.val);
+                               /* read the following character, either newline or ; */
+                               if (lex_scan(&token TSRMLS_CC) != T_WHITESPACE) {
+                                       zend_write(LANG_SCNG(yy_text), LANG_SCNG(yy_leng));
                                }
-                               break;
-                       
+                               zend_write("\n", sizeof("\n") - 1);
+                               prev_space = 1;
+                               token.type = 0;
+                               continue;
+
                        default:
                                zend_write(LANG_SCNG(yy_text), LANG_SCNG(yy_leng));
                                break;
index af4059fef7d0e53bb09b9212e44f58faca9788e0..830fae6c7f1c32fec22dd639ff6855688507ce40 100644 (file)
@@ -1733,7 +1733,6 @@ NEWLINE ("\r"|"\n"|"\r\n")
 
 <ST_HEREDOC>^{LABEL}(";")?{NEWLINE} {
        int label_len;
-       unsigned char unput_semicolon;
 
        CG(zend_lineno)++;
        if (yytext[yyleng-2]=='\r') {
@@ -1744,17 +1743,12 @@ NEWLINE ("\r"|"\n"|"\r\n")
 
        if (yytext[label_len-1]==';') {
                label_len--;
-               unput_semicolon=1;
-       } else{
-               unput_semicolon=0;
        }
 
        if (label_len==CG(heredoc_len) && !memcmp(yytext, CG(heredoc), label_len)) {
                zendlval->value.str.val = estrndup(yytext, label_len); /* unput destroys yytext */
                zendlval->value.str.len = label_len;
-               if (unput_semicolon) {
-                       unput(';');
-               }
+               yyless(yyleng - (yyleng - label_len));
                efree(CG(heredoc));
                CG(heredoc)=NULL;
                CG(heredoc_len)=0;
index 7480aa2f59f90e118fc6ebc9dc14c1d91187f0c6..679ffe3c37ed299f90962cb4510c05cf5d501d2f 100644 (file)
@@ -14,11 +14,11 @@ DDDD;
 var_dump(token_get_all($str));
 ?>
 --EXPECTF--
-array(17) {
+array(19) {
   [0]=>
   array(2) {
     [0]=>
-    int(%d)
+    int(367)
     [1]=>
     string(6) "<?php
 "
@@ -26,7 +26,7 @@ array(17) {
   [1]=>
   array(2) {
     [0]=>
-    int(%d)
+    int(309)
     [1]=>
     string(2) "$x"
   }
@@ -35,7 +35,7 @@ array(17) {
   [3]=>
   array(2) {
     [0]=>
-    int(%d)
+    int(371)
     [1]=>
     string(6) "<<<DD
 "
@@ -43,7 +43,7 @@ array(17) {
   [4]=>
   array(2) {
     [0]=>
-    int(%d)
+    int(307)
     [1]=>
     string(13) "jhdsjkfhjdsh
 "
@@ -51,67 +51,83 @@ array(17) {
   [5]=>
   array(2) {
     [0]=>
-    int(%d)
+    int(372)
     [1]=>
     string(2) "DD"
   }
   [6]=>
-  string(1) "."
+  array(2) {
+    [0]=>
+    int(370)
+    [1]=>
+    string(1) "
+"
+  }
   [7]=>
+  string(1) "."
+  [8]=>
   array(2) {
     [0]=>
-    int(%d)
+    int(315)
     [1]=>
     string(2) """"
   }
-  [8]=>
-  string(1) ";"
   [9]=>
+  string(1) ";"
+  [10]=>
   array(2) {
     [0]=>
-    int(%d)
+    int(370)
     [1]=>
     string(1) "
 "
   }
-  [10]=>
+  [11]=>
   array(2) {
     [0]=>
-    int(%d)
+    int(309)
     [1]=>
     string(2) "$a"
   }
-  [11]=>
-  string(1) "="
   [12]=>
+  string(1) "="
+  [13]=>
   array(2) {
     [0]=>
-    int(%d)
+    int(371)
     [1]=>
     string(8) "<<<DDDD
 "
   }
-  [13]=>
+  [14]=>
   array(2) {
     [0]=>
-    int(%d)
+    int(307)
     [1]=>
     string(13) "jhdsjkfhjdsh
 "
   }
-  [14]=>
+  [15]=>
   array(2) {
     [0]=>
-    int(%d)
+    int(372)
     [1]=>
     string(4) "DDDD"
   }
-  [15]=>
-  string(1) ";"
   [16]=>
+  string(1) ";"
+  [17]=>
+  array(2) {
+    [0]=>
+    int(370)
+    [1]=>
+    string(1) "
+"
+  }
+  [18]=>
   array(2) {
     [0]=>
-    int(%d)
+    int(369)
     [1]=>
     string(2) "?>"
   }