Skip to content

Commit

Permalink
Don't split T_INLINE_HTML at partial PHP tag
Browse files Browse the repository at this point in the history
If <?php occurs without required trailing whitespace, we should keep
it as part of a single T_INLINE_HTML region.
  • Loading branch information
nikic committed Jul 12, 2019
1 parent 79b5b1a commit 0d568b9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Zend/zend_language_scanner.l
Expand Up @@ -2059,8 +2059,12 @@ inline_char_handler:
}

if (*YYCURSOR == '?') {
if (CG(short_tags) || !strncasecmp((char*)YYCURSOR + 1, "php", 3) || (*(YYCURSOR + 1) == '=')) { /* Assume [ \t\n\r] follows "php" */

if (CG(short_tags) /* <? */
|| (*(YYCURSOR + 1) == '=') /* <?= */
|| (!strncasecmp((char*)YYCURSOR + 1, "php", 3) && /* <?php[ \t\r\n] */
(YYCURSOR[4] == ' ' || YYCURSOR[4] == '\t' ||
YYCURSOR[4] == '\n' || YYCURSOR[4] == '\r'))
) {
YYCURSOR--;
break;
}
Expand Down
24 changes: 24 additions & 0 deletions ext/tokenizer/no_inline_html_split.phpt
@@ -0,0 +1,24 @@
--TEST--
Inline HTML should not be split at partial PHP tags
--INI--
short_open_tag=0
--FILE--
<?php

var_dump(token_get_all(<<<'PHP'
Foo<?phpBar
PHP));

?>
--EXPECTF--
array(1) {
[0]=>
array(3) {
[0]=>
int(%d)
[1]=>
string(11) "Foo<?phpBar"
[2]=>
int(1)
}
}

0 comments on commit 0d568b9

Please sign in to comment.