Skip to content

ProperEscapingFunction: allow for comma's in first short open echo tag expression#675

Merged
rebeccahum merged 1 commit intodevelopfrom
fix/671-properescaping-open-with-echo
Apr 22, 2021
Merged

ProperEscapingFunction: allow for comma's in first short open echo tag expression#675
rebeccahum merged 1 commit intodevelopfrom
fix/671-properescaping-open-with-echo

Conversation

@jrfnl
Copy link
Collaborator

@jrfnl jrfnl commented Apr 22, 2021

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

@jrfnl jrfnl added this to the 2.3.1 milestone Apr 22, 2021
@jrfnl jrfnl requested a review from a team as a code owner April 22, 2021 03:41
…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
@jrfnl jrfnl force-pushed the fix/671-properescaping-open-with-echo branch from f8f34bd to c3c2bce Compare April 22, 2021 05:34
@jrfnl
Copy link
Collaborator Author

jrfnl commented Apr 22, 2021

Rebased for merge conflicts (without changes other than to resolve the conflicts)

@rebeccahum rebeccahum merged commit cbb2195 into develop Apr 22, 2021
@rebeccahum rebeccahum deleted the fix/671-properescaping-open-with-echo branch April 22, 2021 16:48
@shvlv shvlv mentioned this pull request Jan 10, 2023
2 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ProperEscapingFunction: account for T_OPEN_TAG_WITH_ECHO

2 participants

Comments