Page MenuHomePhabricator

Don't eat whitespace after T_OPEN_TAG
ClosedPublic

Authored by joshuaspence on Aug 13 2015, 10:20 PM.
Tags
None
Referenced Files
Unknown Object (File)
Wed, Apr 17, 3:04 PM
Unknown Object (File)
Mon, Apr 8, 4:27 AM
Unknown Object (File)
Fri, Apr 5, 9:45 PM
Unknown Object (File)
Fri, Apr 5, 7:47 PM
Unknown Object (File)
Mon, Apr 1, 2:06 AM
Unknown Object (File)
Fri, Mar 29, 7:46 AM
Unknown Object (File)
Mar 6 2024, 4:43 AM
Unknown Object (File)
Feb 16 2024, 2:31 AM
Subscribers

Details

Summary

Currently the scanner eats whitespace after <?php but not after <?. This means that <?php tokenises to T_OPEN_TAG (see https://secure.phabricator.com/xhpast/view/853/) whereas <? tokenises to T_OPEN_TAG, T_WHITESPACE (see https://secure.phabricator.com/xhpast/view/854/).

Test Plan
BeforeAfter
xhpast-before.png (848×1 px, 54 KB)
xhpast-after.png (848×1 px, 54 KB)

Diff Detail

Repository
rPHU libphutil
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

joshuaspence retitled this revision from to Don't eat whitespace after T_OPEN_TAG.
joshuaspence updated this object.
joshuaspence edited the test plan for this revision. (Show Details)
joshuaspence added a reviewer: epriestley.
epriestley edited edge metadata.

Does this parse this input:

<?phpnot

...as containing a T_OPEN_TAG? It should not, since PHP will only recognize <?php as a T_OPEN_TAG if it is followed by whitespace.

This revision now requires changes to proceed.Aug 27 2015, 11:44 AM

That is, with short_open_tag=1, this is a PHP script which prints "2":

<?echo 1+1;

While this is just a block of T_INLINE_HTML and prints the file content literally:

<?phpecho 1+1;

Hmm, it looks like <?phpecho 1+1; is a syntax error according to the current XHPAST:

> echo '<?phpecho 1+1;' | ./support/xhpast/xhpast 
XHPAST Parse Error: syntax error, unexpected T_LNUMBER on line 1
joshuaspence edited edge metadata.

Use a lookahead

joshuaspence edited edge metadata.

Forgot generated files

Hmm, it looks like <?phpecho 1+1; is a syntax error according to the current XHPAST:

> echo '<?phpecho 1+1;' | ./support/xhpast/xhpast 
XHPAST Parse Error: syntax error, unexpected T_LNUMBER on line 1

Filed T9286 for this.

epriestley edited edge metadata.
This revision is now accepted and ready to land.Aug 30 2015, 12:37 PM
This revision was automatically updated to reflect the committed changes.