Skip to content

Align highlight_string|file with HTML standard and modern browsers #11913

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions Zend/tests/bug35655.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,10 @@ EOT
highlight_string($code);
?>
--EXPECT--
<code><span style="color: #000000">
<br /><span style="color: #0000BB">&lt;?php<br />&nbsp;&nbsp;$x&nbsp;</span><span style="color: #007700">=&nbsp;&lt;&lt;&lt;EOT<br /></span><span style="color: #DD0000">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>
<pre><code style="color: #000000">
<span style="color: #0000BB">&lt;?php
$x </span><span style="color: #007700">= &lt;&lt;&lt;EOT
</span><span style="color: #DD0000">some string
</span><span style="color: #007700">EOT
</span><span style="color: #0000BB">$y </span><span style="color: #007700">= </span><span style="color: #0000BB">2</span><span style="color: #007700">;
</span><span style="color: #0000BB">?&gt;</span></code></pre>
5 changes: 1 addition & 4 deletions Zend/tests/bug42767.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,4 @@ highlight.html = #000000
highlight_string('<?php /*some comment..');
?>
--EXPECT--
<code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php&nbsp;</span><span style="color: #FF8000">/*some&nbsp;comment..</span>
</span>
</code>
<pre><code style="color: #000000"><span style="color: #0000BB">&lt;?php </span><span style="color: #FF8000">/*some comment..</span></code></pre>
6 changes: 2 additions & 4 deletions Zend/tests/bug71086.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,5 @@ var_dump($highlightedString);

?>
--EXPECT--
string(169) "<code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php&nbsp;<br />&nbsp;09&nbsp;09&nbsp;09</span><span style="color: #007700">;</span>
</span>
</code>"
string(139) "<pre><code style="color: #000000"><span style="color: #0000BB">&lt;?php
09 09 09</span><span style="color: #007700">;</span></code></pre>"
10 changes: 6 additions & 4 deletions Zend/tests/nowdoc_013.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ EOF;
highlight_string($code);
?>
--EXPECT--
<code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />&nbsp;&nbsp;$x&nbsp;</span><span style="color: #007700">=&nbsp;&lt;&lt;&lt;'EOT'<br /></span><span style="color: #DD0000">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>
<pre><code style="color: #000000"><span style="color: #0000BB">&lt;?php
$x </span><span style="color: #007700">= &lt;&lt;&lt;'EOT'
</span><span style="color: #DD0000">some string
</span><span style="color: #007700">EOT
</span><span style="color: #0000BB">$y </span><span style="color: #007700">= </span><span style="color: #0000BB">2</span><span style="color: #007700">;
</span><span style="color: #0000BB">?&gt;</span></code></pre>
9 changes: 5 additions & 4 deletions Zend/tests/nowdoc_014.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ EOF;
highlight_string($code);
?>
--EXPECT--
<code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />&nbsp;&nbsp;$x&nbsp;</span><span style="color: #007700">=&nbsp;&lt;&lt;&lt;'EOT'<br />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>
<pre><code style="color: #000000"><span style="color: #0000BB">&lt;?php
$x </span><span style="color: #007700">= &lt;&lt;&lt;'EOT'
EOT
</span><span style="color: #0000BB">$y </span><span style="color: #007700">= </span><span style="color: #0000BB">2</span><span style="color: #007700">;
</span><span style="color: #0000BB">?&gt;</span></code></pre>
16 changes: 4 additions & 12 deletions Zend/zend_highlight.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
ZEND_API void zend_html_putc(char c)
{
switch (c) {
case '\n':
ZEND_PUTS("<br />");
break;
case '<':
ZEND_PUTS("&lt;");
break;
Expand All @@ -40,11 +37,8 @@ ZEND_API void zend_html_putc(char c)
case '&':
ZEND_PUTS("&amp;");
break;
case ' ':
ZEND_PUTS("&nbsp;");
break;
case '\t':
ZEND_PUTS("&nbsp;&nbsp;&nbsp;&nbsp;");
ZEND_PUTS(" ");
Comment on lines 40 to +41
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if I'm a fan of replacing tabs by 4 spaces, but that's by the by.

break;
default:
ZEND_PUTC(c);
Expand Down Expand Up @@ -88,8 +82,7 @@ ZEND_API void zend_highlight(zend_syntax_highlighter_ini *syntax_highlighter_ini
char *last_color = syntax_highlighter_ini->highlight_html;
char *next_color;

zend_printf("<code>");
zend_printf("<span style=\"color: %s\">\n", last_color);
zend_printf("<pre><code style=\"color: %s\">", last_color);
/* highlight stuff coming back from zendlex() */
while ((token_type=lex_scan(&token, NULL))) {
switch (token_type) {
Expand Down Expand Up @@ -162,10 +155,9 @@ ZEND_API void zend_highlight(zend_syntax_highlighter_ini *syntax_highlighter_ini
}

if (last_color != syntax_highlighter_ini->highlight_html) {
zend_printf("</span>\n");
zend_printf("</span>");
}
zend_printf("</span>\n");
zend_printf("</code>");
zend_printf("</code></pre>");

/* Discard parse errors thrown during tokenization */
zend_clear_exception();
Expand Down
5 changes: 1 addition & 4 deletions ext/phar/tests/cache_list/frontcontroller15.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,4 @@ files/frontcontroller8.phar
--EXPECTHEADERS--
Content-type: text/html; charset=UTF-8
--EXPECT--
<code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php&nbsp;</span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">hio</span><span style="color: #007700">(){}</span>
</span>
</code>
<pre><code style="color: #000000"><span style="color: #0000BB">&lt;?php </span><span style="color: #007700">function </span><span style="color: #0000BB">hio</span><span style="color: #007700">(){}</span></code></pre>
5 changes: 1 addition & 4 deletions ext/phar/tests/cache_list/frontcontroller3.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,4 @@ files/frontcontroller.phar
--EXPECTHEADERS--
Content-type: text/html; charset=UTF-8
--EXPECT--
<code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php&nbsp;</span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">hio</span><span style="color: #007700">(){}</span>
</span>
</code>
<pre><code style="color: #000000"><span style="color: #0000BB">&lt;?php </span><span style="color: #007700">function </span><span style="color: #0000BB">hio</span><span style="color: #007700">(){}</span></code></pre>
5 changes: 1 addition & 4 deletions ext/phar/tests/cache_list/frontcontroller9.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,4 @@ files/frontcontroller3.phar
--EXPECTHEADERS--
Content-type: text/html; charset=UTF-8
--EXPECT--
<code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php&nbsp;</span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">hio</span><span style="color: #007700">(){}</span>
</span>
</code>
<pre><code style="color: #000000"><span style="color: #0000BB">&lt;?php </span><span style="color: #007700">function </span><span style="color: #0000BB">hio</span><span style="color: #007700">(){}</span></code></pre>
5 changes: 1 addition & 4 deletions ext/phar/tests/frontcontroller15.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,4 @@ files/frontcontroller8.phar
--EXPECTHEADERS--
Content-type: text/html; charset=UTF-8
--EXPECT--
<code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php&nbsp;</span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">hio</span><span style="color: #007700">(){}</span>
</span>
</code>
<pre><code style="color: #000000"><span style="color: #0000BB">&lt;?php </span><span style="color: #007700">function </span><span style="color: #0000BB">hio</span><span style="color: #007700">(){}</span></code></pre>
5 changes: 1 addition & 4 deletions ext/phar/tests/frontcontroller3.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,4 @@ files/frontcontroller.phar
--EXPECTHEADERS--
Content-type: text/html; charset=UTF-8
--EXPECT--
<code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php&nbsp;</span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">hio</span><span style="color: #007700">(){}</span>
</span>
</code>
<pre><code style="color: #000000"><span style="color: #0000BB">&lt;?php </span><span style="color: #007700">function </span><span style="color: #0000BB">hio</span><span style="color: #007700">(){}</span></code></pre>
5 changes: 1 addition & 4 deletions ext/phar/tests/frontcontroller9.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,4 @@ files/frontcontroller3.phar
--EXPECTHEADERS--
Content-type: text/html; charset=UTF-8
--EXPECT--
<code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php&nbsp;</span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">hio</span><span style="color: #007700">(){}</span>
</span>
</code>
<pre><code style="color: #000000"><span style="color: #0000BB">&lt;?php </span><span style="color: #007700">function </span><span style="color: #0000BB">hio</span><span style="color: #007700">(){}</span></code></pre>
5 changes: 1 addition & 4 deletions ext/phar/tests/tar/frontcontroller15.phar.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,4 @@ files/frontcontroller8.phar.tar
--EXPECTHEADERS--
Content-type: text/html; charset=UTF-8
--EXPECT--
<code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php&nbsp;</span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">hio</span><span style="color: #007700">(){}</span>
</span>
</code>
<pre><code style="color: #000000"><span style="color: #0000BB">&lt;?php </span><span style="color: #007700">function </span><span style="color: #0000BB">hio</span><span style="color: #007700">(){}</span></code></pre>
5 changes: 1 addition & 4 deletions ext/phar/tests/tar/frontcontroller3.phar.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,4 @@ files/frontcontroller.phar.tar
--EXPECTHEADERS--
Content-type: text/html; charset=UTF-8
--EXPECT--
<code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php&nbsp;</span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">hio</span><span style="color: #007700">(){}</span>
</span>
</code>
<pre><code style="color: #000000"><span style="color: #0000BB">&lt;?php </span><span style="color: #007700">function </span><span style="color: #0000BB">hio</span><span style="color: #007700">(){}</span></code></pre>
5 changes: 1 addition & 4 deletions ext/phar/tests/tar/frontcontroller9.phar.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,4 @@ files/frontcontroller3.phar.tar
--EXPECTHEADERS--
Content-type: text/html; charset=UTF-8
--EXPECT--
<code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php&nbsp;</span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">hio</span><span style="color: #007700">(){}</span>
</span>
</code>
<pre><code style="color: #000000"><span style="color: #0000BB">&lt;?php </span><span style="color: #007700">function </span><span style="color: #0000BB">hio</span><span style="color: #007700">(){}</span></code></pre>
5 changes: 1 addition & 4 deletions ext/phar/tests/zip/frontcontroller15.phar.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,4 @@ files/frontcontroller8.phar.zip
--EXPECTHEADERS--
Content-type: text/html; charset=UTF-8
--EXPECT--
<code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php&nbsp;</span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">hio</span><span style="color: #007700">(){}</span>
</span>
</code>
<pre><code style="color: #000000"><span style="color: #0000BB">&lt;?php </span><span style="color: #007700">function </span><span style="color: #0000BB">hio</span><span style="color: #007700">(){}</span></code></pre>
5 changes: 1 addition & 4 deletions ext/phar/tests/zip/frontcontroller3.phar.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,4 @@ files/frontcontroller.phar.zip
--EXPECTHEADERS--
Content-type: text/html; charset=UTF-8
--EXPECT--
<code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php&nbsp;</span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">hio</span><span style="color: #007700">(){}</span>
</span>
</code>
<pre><code style="color: #000000"><span style="color: #0000BB">&lt;?php </span><span style="color: #007700">function </span><span style="color: #0000BB">hio</span><span style="color: #007700">(){}</span></code></pre>
5 changes: 1 addition & 4 deletions ext/phar/tests/zip/frontcontroller9.phar.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,4 @@ files/frontcontroller3.phar.zip
--EXPECTHEADERS--
Content-type: text/html; charset=UTF-8
--EXPECT--
<code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php&nbsp;</span><span style="color: #007700">function&nbsp;</span><span style="color: #0000BB">hio</span><span style="color: #007700">(){}</span>
</span>
</code>
<pre><code style="color: #000000"><span style="color: #0000BB">&lt;?php </span><span style="color: #007700">function </span><span style="color: #0000BB">hio</span><span style="color: #007700">(){}</span></code></pre>
12 changes: 9 additions & 3 deletions ext/standard/tests/general_functions/highlight_heredoc.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ DDDD;
highlight_string($str);
?>
--EXPECT--
<code><span style="color: #000000">
<br />$x=&lt;&lt;&lt;DD<br />jhdsjkfhjdsh<br />DD<br />."";<br />$a=&lt;&lt;&lt;DDDD<br />jhdsjkfhjdsh<br />DDDD;<br /></span>
</code>
<pre><code style="color: #000000">
$x=&lt;&lt;&lt;DD
jhdsjkfhjdsh
DD
."";
$a=&lt;&lt;&lt;DDDD
jhdsjkfhjdsh
DDDD;
</code></pre>
22 changes: 10 additions & 12 deletions ext/standard/tests/strings/highlight_file.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,14 @@ Warning: highlight_file(%shighlight_file.dat): Failed to open stream: No such fi

Warning: highlight_file(): Failed opening '%shighlight_file.dat' for highlighting in %s on line %d
bool(false)
<code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php&nbsp;</span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"test"</span><span style="color: #007700">;&nbsp;</span><span style="color: #0000BB">?&gt;</span>
</span>
</code>bool(true)
<code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php&nbsp;</span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"test&nbsp;?&gt;</span>
</span>
</code>bool(true)
<code><span style="color: #000000">
<br /><span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">class&nbsp;</span><span style="color: #0000BB">test&nbsp;</span><span style="color: #007700">{<br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;</span><span style="color: #0000BB">$var&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;private&nbsp;function&nbsp;</span><span style="color: #0000BB">foo</span><span style="color: #007700">()&nbsp;{&nbsp;echo&nbsp;</span><span style="color: #DD0000">"foo"</span><span style="color: #007700">;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;public&nbsp;function&nbsp;</span><span style="color: #0000BB">bar</span><span style="color: #007700">()&nbsp;{&nbsp;</span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">test</span><span style="color: #007700">::</span><span style="color: #0000BB">foo</span><span style="color: #007700">());&nbsp;}<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code>bool(true)
<pre><code style="color: #000000"><span style="color: #0000BB">&lt;?php </span><span style="color: #007700">echo </span><span style="color: #DD0000">"test"</span><span style="color: #007700">; </span><span style="color: #0000BB">?&gt;</span></code></pre>bool(true)
<pre><code style="color: #000000"><span style="color: #0000BB">&lt;?php </span><span style="color: #007700">echo </span><span style="color: #DD0000">"test ?&gt;</span></code></pre>bool(true)
<pre><code style="color: #000000">
<span style="color: #0000BB">&lt;?php
</span><span style="color: #007700">class </span><span style="color: #0000BB">test </span><span style="color: #007700">{
public </span><span style="color: #0000BB">$var </span><span style="color: #007700">= </span><span style="color: #0000BB">1</span><span style="color: #007700">;
private function </span><span style="color: #0000BB">foo</span><span style="color: #007700">() { echo </span><span style="color: #DD0000">"foo"</span><span style="color: #007700">; }
public function </span><span style="color: #0000BB">bar</span><span style="color: #007700">() { </span><span style="color: #0000BB">var_dump</span><span style="color: #007700">(</span><span style="color: #0000BB">test</span><span style="color: #007700">::</span><span style="color: #0000BB">foo</span><span style="color: #007700">()); }
}
</span><span style="color: #0000BB">?&gt;</span></code></pre>bool(true)
Done
20 changes: 16 additions & 4 deletions ext/standard/tests/strings/show_source_basic.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,19 @@ show_source(__FILE__);
?>
--EXPECT--
*** Test by calling method or function with its expected arguments ***
<code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #007700">echo&nbsp;</span><span style="color: #DD0000">"***&nbsp;Test&nbsp;by&nbsp;calling&nbsp;method&nbsp;or&nbsp;function&nbsp;with&nbsp;its&nbsp;expected&nbsp;arguments&nbsp;***\n"</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$foo&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'bar'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$baz&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"something&nbsp;"</span><span style="color: #007700">.</span><span style="color: #0000BB">$foo</span><span style="color: #007700">.</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;<br /><br />if&nbsp;(&nbsp;</span><span style="color: #0000BB">$foo&nbsp;</span><span style="color: #007700">==&nbsp;</span><span style="color: #DD0000">'bar'&nbsp;</span><span style="color: #007700">)<br />{<br />&nbsp;&nbsp;</span><span style="color: #0000BB">$baz&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">'baz'</span><span style="color: #007700">;<br />}<br /><br />&nbsp;</span><span style="color: #FF8000">/*&nbsp;some&nbsp;code&nbsp;here&nbsp;*/<br /><br /></span><span style="color: #0000BB">show_source</span><span style="color: #007700">(</span><span style="color: #0000BB">__FILE__</span><span style="color: #007700">);<br /><br /></span><span style="color: #0000BB">?&gt;<br /></span>
</span>
</code>
<pre><code style="color: #000000"><span style="color: #0000BB">&lt;?php
</span><span style="color: #007700">echo </span><span style="color: #DD0000">"*** Test by calling method or function with its expected arguments ***\n"</span><span style="color: #007700">;
</span><span style="color: #0000BB">$foo </span><span style="color: #007700">= </span><span style="color: #DD0000">'bar'</span><span style="color: #007700">;
</span><span style="color: #0000BB">$baz </span><span style="color: #007700">= </span><span style="color: #DD0000">"something "</span><span style="color: #007700">.</span><span style="color: #0000BB">$foo</span><span style="color: #007700">.</span><span style="color: #DD0000">"\n"</span><span style="color: #007700">;

if ( </span><span style="color: #0000BB">$foo </span><span style="color: #007700">== </span><span style="color: #DD0000">'bar' </span><span style="color: #007700">)
{
</span><span style="color: #0000BB">$baz </span><span style="color: #007700">= </span><span style="color: #DD0000">'baz'</span><span style="color: #007700">;
}

</span><span style="color: #FF8000">/* some code here */

</span><span style="color: #0000BB">show_source</span><span style="color: #007700">(</span><span style="color: #0000BB">__FILE__</span><span style="color: #007700">);

</span><span style="color: #0000BB">?&gt;
</span></code></pre>
Loading