ProperEscapingFunction: allow for comma's in first short open echo tag expression#675
Merged
rebeccahum merged 1 commit intodevelopfrom Apr 22, 2021
Merged
Conversation
…g expression Short open echo tags will act as an echo for the first expression and allow for passing multiple comma-separated parameters. However, short open echo tags also allow for additional statements after, but those have to be full PHP statements, not expressions. So, the `T_COMMA` token should be allowed and skipped over in the first expression, but not for subsequent statements following a short open echo tag. `$phpcsFile->findStartOfStatement()` unfortunately is useless - even in its fixed-up form as will be in PHPCS 3.6.1-, as it will return the first token in the statement, which can be anything - variable, text string - without any indication of whether this is the start of a normal statement or a short open echo expression. So, if we used that, we'd still need to walk back from every start of statement to the previous non-empty to see if it is the short open echo tag. So to solve this conundrum, I've implemented a simple tracking system which will keep track of whether we have seen a short open echo tag and are within the first statement (expression) after this tag and will add the `T_COMMA` token if those conditions are fulfilled. Fixes 671
f8f34bd to
c3c2bce
Compare
Collaborator
Author
|
Rebased for merge conflicts (without changes other than to resolve the conflicts) |
rebeccahum
approved these changes
Apr 22, 2021
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Short open echo tags will act as an echo for the first expression and allow for passing multiple comma-separated parameters.
However, short open echo tags also allow for additional statements after, but those have to be full PHP statements, not expressions.
So, the
T_COMMAtoken should be allowed and skipped over in the first expression, but not for subsequent statements following a short open echo tag.$phpcsFile->findStartOfStatement()unfortunately is useless - even in its fixed-up form as will be in PHPCS 3.6.1-, as it will return the first token in the statement, which can be anything - variable, text string - without any indication of whether this is the start of a normal statement or a short open echo expression.So, if we used that, we'd still need to walk back from every start of statement to the previous non-empty to see if it is the short open echo tag.
So to solve this conundrum, I've implemented a simple tracking system which will keep track of whether we have seen a short open echo tag and are within the first statement (expression) after this tag and will add the
T_COMMAtoken if those conditions are fulfilled.Fixes #671