Skip to content

Commit b26d5f6

Browse files
author
Ilia Alshanetsky
committed
Fixed bug #42767 (highlight_string() truncates trailing comment)
1 parent 2ff92b5 commit b26d5f6

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

Zend/tests/bug42767.phpt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
--TEST--
2+
Bug #42767 (highlight_string() truncates trailing comments)
3+
--FILE--
4+
<?php
5+
highlight_string('<?php /*some comment..');
6+
?>
7+
--EXPECT--
8+
<code><span style="color: #000000">
9+
<span style="color: #0000BB">&lt;?php&nbsp;</span><span style="color: #FF8000">/*some&nbsp;comment..</span>
10+
</span>
11+
</code>

Zend/zend_highlight.c

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,19 @@ ZEND_API void zend_highlight(zend_syntax_highlighter_ini *syntax_highlighter_ini
177177
}
178178
token.type = 0;
179179
}
180+
181+
/* handler for trailing comments, see bug #42767 */
182+
if (LANG_SCNG(yy_leng) && LANG_SCNG(_yy_more_len)) {
183+
if (last_color != syntax_highlighter_ini->highlight_comment) {
184+
if (last_color != syntax_highlighter_ini->highlight_html) {
185+
zend_printf("</span>");
186+
}
187+
if (syntax_highlighter_ini->highlight_comment != syntax_highlighter_ini->highlight_html) {
188+
zend_printf("<span style=\"color: %s\">", syntax_highlighter_ini->highlight_comment);
189+
}
190+
}
191+
zend_html_puts(LANG_SCNG(yy_text), LANG_SCNG(_yy_more_len) TSRMLS_CC);
192+
}
180193
done:
181194
if (last_color != syntax_highlighter_ini->highlight_html) {
182195
zend_printf("</span>\n");
@@ -185,8 +198,6 @@ ZEND_API void zend_highlight(zend_syntax_highlighter_ini *syntax_highlighter_ini
185198
zend_printf("</code>");
186199
}
187200

188-
189-
190201
ZEND_API void zend_strip(TSRMLS_D)
191202
{
192203
zval token;

0 commit comments

Comments
 (0)