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
F18832220: D13890.id.diff
Sat, Oct 25, 8:13 PM
F18826769: D13890.diff
Fri, Oct 24, 5:40 AM
F18809493: D13890.id33533.diff
Sun, Oct 19, 2:31 PM
F18777291: D13890.id.diff
Sat, Oct 11, 1:54 AM
F18749484: D13890.diff
Oct 4 2025, 4:00 AM
F18749483: D13890.diff
Oct 4 2025, 4:00 AM
F18749474: D13890.diff
Oct 4 2025, 3:59 AM
F18749466: D13890.diff
Oct 4 2025, 3:59 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.