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
F18301627: D13890.id33535.diff
Sat, Aug 23, 8:10 PM
F18301626: D13890.id33533.diff
Sat, Aug 23, 8:10 PM
F18301625: D13890.id33876.diff
Sat, Aug 23, 8:10 PM
F18301624: D13890.id33845.diff
Sat, Aug 23, 8:10 PM
F18301623: D13890.id33840.diff
Sat, Aug 23, 8:09 PM
F18107507: D13890.id33840.diff
Mon, Aug 11, 1:10 AM
F18084872: D13890.id33535.diff
Tue, Aug 5, 6:09 PM
F18053569: D13890.id33880.diff
Mon, Aug 4, 5:11 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.