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)
Sat, Nov 23, 5:32 PM
Unknown Object (File)
Wed, Nov 20, 2:10 PM
Unknown Object (File)
Tue, Nov 12, 7:20 AM
Unknown Object (File)
Wed, Nov 6, 6:24 PM
Unknown Object (File)
Wed, Nov 6, 6:24 PM
Unknown Object (File)
Wed, Nov 6, 6:23 PM
Unknown Object (File)
Mon, Nov 4, 7:45 AM
Unknown Object (File)
Sun, Nov 3, 11:41 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
Branch
master
Lint
Lint Passed
Unit
Tests Passed
Build Status
Buildable 7621
Build 8282: [Placeholder Plan] Wait for 30 Seconds
Build 8280: arc lint + arc unit

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.