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
F18084872: D13890.id33535.diff
Tue, Aug 5, 6:09 PM
F18053569: D13890.id33880.diff
Mon, Aug 4, 5:11 AM
F17937670: D13890.id33533.diff
Thu, Jul 31, 1:26 AM
F17933963: D13890.id.diff
Wed, Jul 30, 9:46 PM
F17924450: D13890.id33845.diff
Wed, Jul 30, 10:00 AM
F17899529: D13890.diff
Tue, Jul 29, 8:40 AM
F17728812: D13890.id33880.diff
Sat, Jul 19, 5:07 PM
F17632806: D13890.diff
Thu, Jul 10, 3:55 PM
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.