Bug #70983 [Opn->Wfx]: commenting a printf line causes script to fail with "Unexpected end of file"
| From: | krakjoe@php.net | Date: | Mon, 09 Jan 2017 05:48:53 +0000 |
| Subject: | Bug #70983 [Opn->Wfx]: commenting a printf line causes script to fail with "Unexpected end of file" | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-206425@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=70983&edit=1
ID: 70983
Updated by: krakjoe@php.net
Reported by: php at rossw dot net
Summary: commenting a printf line causes script to fail with
"Unexpected end of file"
-Status: Open
+Status: Wont fix
Type: Bug
Package: Reproducible crash
Operating System: FreeBSD 10.2
PHP Version: 5.6.16
Block user comment: N
Private report: N
New Comment:
Since this is against a security fix only branch, and since a patch against a supported branch would
need to be different, please can you open a PR on github against a supported branch.
Previous Comments:
------------------------------------------------------------------------
[2016-07-26 16:05:40] dave at mudsite dot com
I understand this request. PHP ought to know if this is a single-line execute, and handle
accordingly.
<?php echo "hello"; // comment ?> output
and
<?= echo "hello"; // comment ?> output
should each run with output:
hello output
That said, the request here:
<?php
if (foo) {
// ?>
}
}
?>
Should not throw a syntax error. I have no idea what the consensus on this kind of issue is,
however, (i've done) and it would be simple enough to track what line <?php, or <?, or
<?= start on, and what line we see // ?>, and if they aren't the same, then ignore the
?> inside the comment.
ie:
if (*YYCURSOR == '>' && (CG(zend_opentag_lineno) == CG(zend_lineno))) {
------------------------------------------------------------------------
[2015-12-02 12:09:39] codekestrel at googlemail dot com
That behaviour is explicitly defined here:
<ST_IN_SCRIPTING>"#"|"//" {
while (YYCURSOR < YYLIMIT) {
switch (*YYCURSOR++) {
case '\r':
if (*YYCURSOR == '\n') {
YYCURSOR++;
}
/* fall through */
case '\n':
CG(zend_lineno)++;
break;
case '?':
if (*YYCURSOR == '>') {
YYCURSOR--;
break;
}
/* fall through */
default:
continue;
}
break;
}
yyleng = YYCURSOR - SCNG(yy_text);
RETURN_TOKEN(T_COMMENT);
}
Removing the "case '?':" clause would break the following inline code:
<?php echo "Hello, World!"; // my comment ?> Remainder
Which should print: Hello, World! Remainder
Everything on the same line after the comment including after the closing tag are commented out.
------------------------------------------------------------------------
[2015-11-27 06:35:20] php at rossw dot net
Description:
------------
A quoted string containing ?> is treated correctly inside an active code block, but causes errors
due to being handled differently if the line is commented out.
I can see how it could be argued that ?> should not appear, but there are times you might
actually WANT to print it. Simply commenting out the line should not materially alter the way the
(otherwise perfectly healthy) script runs.
Test script:
---------------
<?php
printf("This is a test\n");
if(1 > 0)
{
// printf("?> Debug code\n");
printf("Got here\n");
}
printf("Finished\n");
?>
Expected result:
----------------
php is seeing the "?> Debug code" as quoted text, and handles it correctly while the
line is not commented. As soon as the line is commented, php is seeing the quoted ?> as the end
of the code and errors.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=70983&edit=1