Skip to content
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

Fix bug in attributes tokenization on PHP < 8.0 (#3294) #3299

Merged
merged 1 commit into from Apr 14, 2021

Conversation

alekitto
Copy link
Contributor

As per title, this fixes the bug described in #3294.

Only if the PHP version is less than 8.0 AND the attribute closer token is not found (not being on the same line or placed after a "?>" token which is interpreted as a php close tag for example), the remainder of the file will be re-tokenized and the attribute closed is searched in the new token stream.
If found the new token stream is injected into the token array and parsing continues, otherwise the re-tokenized stream will be ignored.

@gsherwood gsherwood added this to Idea Bank in PHPCS v3 Development via automation Apr 14, 2021
@gsherwood gsherwood added this to the 3.6.1 milestone Apr 14, 2021
gsherwood added a commit that referenced this pull request Apr 14, 2021
@gsherwood gsherwood merged commit 26a545f into squizlabs:master Apr 14, 2021
PHPCS v3 Development automation moved this from Idea Bank to Ready for Release Apr 14, 2021
@gsherwood
Copy link
Member

Thanks a lot for this fix

jrfnl added a commit to jrfnl/box that referenced this pull request Oct 10, 2021
Up to now, when a Phar was being created using PHP < 8.0 with the PHP compactor enabled, PHP 8.0+ attributes would be incorrectly removed as if they were comments.

This has now been fixed.

Both the solution implemented, as well as the unit tests, are largely inspired by the solution for handling attributes when code is being tokenized on PHP < 8.0, as implemented in `PHP_CodeSniffer` in squizlabs/PHP_CodeSniffer#3203 and squizlabs/PHP_CodeSniffer#3299. Props to alekitto.

Fixes 567

Co-authored-by: Alessandro Chitolina <alekitto@gmail.com>
jrfnl added a commit to jrfnl/box that referenced this pull request Oct 10, 2021
Up to now, when a Phar was being created using PHP < 8.0 with the PHP compactor enabled, PHP 8.0+ attributes would be incorrectly removed as if they were comments.

This has now been fixed.

Both the solution implemented, as well as the unit tests, are largely inspired by the solution for handling attributes when code is being tokenized on PHP < 8.0, as implemented in `PHP_CodeSniffer` in squizlabs/PHP_CodeSniffer#3203 and squizlabs/PHP_CodeSniffer#3299. Props to alekitto.

Fixes 567

Co-authored-by: Alessandro Chitolina <alekitto@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
PHPCS v3 Development
Ready for Release
Development

Successfully merging this pull request may close these issues.

None yet

2 participants