-
Notifications
You must be signed in to change notification settings - Fork 79
Fix handling of HaltCompilerStatement #389
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
525aced
Fix handling of HaltCompilerStatement
TysonAndre 9143577
Rename local variable to $haltCompilerStatement
TysonAndre 2218a40
Add test of invalid __halt_compiler without args
TysonAndre d9e3877
Make HaltCompilerStatement inline html start=fullStart
TysonAndre 8d3d0bb
Put opening brace on the same line as the method
TysonAndre File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
{ | ||
"SourceFileNode": { | ||
"statementList": [ | ||
{ | ||
"InlineHtml": { | ||
"scriptSectionEndTag": null, | ||
"text": null, | ||
"scriptSectionStartTag": { | ||
"kind": "ScriptSectionStartTag", | ||
"textLength": 6 | ||
} | ||
} | ||
}, | ||
{ | ||
"HaltCompilerStatement": { | ||
"haltCompilerKeyword": { | ||
"kind": "HaltCompilerKeyword", | ||
"textLength": 15 | ||
}, | ||
"openParen": { | ||
"kind": "OpenParenToken", | ||
"textLength": 1 | ||
}, | ||
"closeParen": { | ||
"kind": "CloseParenToken", | ||
"textLength": 1 | ||
}, | ||
"semicolon": null, | ||
"data": null | ||
} | ||
}, | ||
{ | ||
"InlineHtml": { | ||
"scriptSectionEndTag": { | ||
"kind": "ScriptSectionEndTag", | ||
"textLength": 3 | ||
}, | ||
"text": null, | ||
"scriptSectionStartTag": null | ||
} | ||
} | ||
], | ||
"endOfFileToken": { | ||
"kind": "EndOfFileToken", | ||
"textLength": 0 | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<?php /* has implicit ';' and no trailing newline byte */ __halt_compiler() ?> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
{ | ||
"SourceFileNode": { | ||
"statementList": [ | ||
{ | ||
"InlineHtml": { | ||
"scriptSectionEndTag": null, | ||
"text": null, | ||
"scriptSectionStartTag": { | ||
"kind": "ScriptSectionStartTag", | ||
"textLength": 6 | ||
} | ||
} | ||
}, | ||
{ | ||
"HaltCompilerStatement": { | ||
"haltCompilerKeyword": { | ||
"kind": "HaltCompilerKeyword", | ||
"textLength": 15 | ||
}, | ||
"openParen": { | ||
"kind": "OpenParenToken", | ||
"textLength": 1 | ||
}, | ||
"closeParen": { | ||
"kind": "CloseParenToken", | ||
"textLength": 1 | ||
}, | ||
"semicolonOrCloseTag": { | ||
"kind": "ScriptSectionEndTag", | ||
"textLength": 2 | ||
}, | ||
"data": null | ||
} | ||
} | ||
], | ||
"endOfFileToken": { | ||
"kind": "EndOfFileToken", | ||
"textLength": 0 | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?php | ||
// A MissingToken should be generated for the missing `;` or close php tag. | ||
// NOTE: token_get_all() will yield up to 3 tokens after T_HALT_COMPILER, | ||
// no matter what those tokens happen to be, so tolerant-php-parser combines unexpected tokens into T_INLINE_HTML | ||
// so that no subsequent statements get emitted. | ||
// (T_HALT_COMPILER is forbidden in other node types) | ||
// In this invalid AST, treat " + 1;\n" as the inline data after the missing semicolon. | ||
__halt_compiler() + 1; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[ | ||
{ | ||
"kind": 0, | ||
"message": "';' expected.", | ||
"start": 482, | ||
"length": 0 | ||
} | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
{ | ||
"SourceFileNode": { | ||
"statementList": [ | ||
{ | ||
"InlineHtml": { | ||
"scriptSectionEndTag": null, | ||
"text": null, | ||
"scriptSectionStartTag": { | ||
"kind": "ScriptSectionStartTag", | ||
"textLength": 6 | ||
} | ||
} | ||
}, | ||
{ | ||
"HaltCompilerStatement": { | ||
"haltCompilerKeyword": { | ||
"kind": "HaltCompilerKeyword", | ||
"textLength": 15 | ||
}, | ||
"openParen": { | ||
"kind": "OpenParenToken", | ||
"textLength": 1 | ||
}, | ||
"closeParen": { | ||
"kind": "CloseParenToken", | ||
"textLength": 1 | ||
}, | ||
"semicolonOrCloseTag": { | ||
"error": "MissingToken", | ||
"kind": "SemicolonToken", | ||
"textLength": 0 | ||
}, | ||
"data": { | ||
"kind": "InlineHtml", | ||
"textLength": 10 | ||
} | ||
} | ||
} | ||
], | ||
"endOfFileToken": { | ||
"kind": "EndOfFileToken", | ||
"textLength": 0 | ||
} | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
<?php | ||
__halt_compiler |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
[ | ||
{ | ||
"kind": 0, | ||
"message": "'(' expected.", | ||
"start": 21, | ||
"length": 0 | ||
}, | ||
{ | ||
"kind": 0, | ||
"message": "')' expected.", | ||
"start": 21, | ||
"length": 0 | ||
}, | ||
{ | ||
"kind": 0, | ||
"message": "';' expected.", | ||
"start": 21, | ||
"length": 0 | ||
} | ||
] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reasoning in updating the tests I'd added in the previous PR is that HaltCompiler should halt the compiler and not parse any more statements, so I'd treat the snippet like
__halt_compiler[();]::foo();
with inline html of::foo();\n
(this token can't be used in other statements/expressions and is a syntax error)
The MissingToken in the original tree were due to token_get_all() returning at most 3 tokens after T_HALT_COMPILER then returning T_INLINE_HTML for the rest