-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 CSS tokenizer #3906
Fix bug in CSS tokenizer #3906
Conversation
@fredden Thanks for this PR. While I'm not keen on putting any more effort into the CSS tokenizer, the outcome of this bug is pretty undesirable, so I'm willing to accept this fix. ✔️ I have confirmed and been able to reproduce the issue. However, looking at the token output, the problem is actually bigger and not really fixed. Originally, the code sample in the description above was tokenized like so:
Take note of token 5, the inserted With this fix applied, the code sample is tokenized as
What I mean to point out by posting these tokenizations is that the comment line tokenization is completely borked for this code sample, what with all lines after the first line getting confused. @fredden Did you notice this ? What is your opinion on this ? As I said above, I'm okay with just accepting this fix as-is and not spending more time on this as CSS tokenizer support will be dropped, but I did want to document this finding. |
@fredden I'm also trying to remember if |
Thanks for looking at this @jrfnl
Yes, I did notice this. I don't yet understand why there's any special-case handling for comments in the CSS tokenizer. I decided to not spend additional brain-power working this out though, as the plan is to delete non-PHP tokenizers for version 4.0. This pull request doesn't make it any worse; I intentionally took a minimal-change approach.
No, I don't think it is; I'll check... Some basic local testing with the three browsers I have installed currently all show that |
@fredden Thanks for checking that. IIRC the CSS tokenizer never had any support for LESS. If it worked, that should be considered coincidental, not by design. As CSS doesn't support the |
I don't think it's valid for the CSS tokenizer to inject a rogue Example of PHP tokenizer handling a parse error without adding an extra
|
@fredden Okay, I'm going to merge this PR as the rogue token output is just weird. Having said that, I would caution that further PRs adding support for LESS to the CSS tokenizer are strongly discouraged. |
Agreed. LESS and CSS are not the same and one shouldn't be parsed as the other. I look forward to version 4.0 where these other-language tokenizers will be gone. |
FYI: this fix is included in today's PHP_CodeSniffer 3.8.0 release. As per #3932, development on PHP_CodeSniffer will continue in the PHPCSStandards/PHP_CodeSniffer repository. If you want to stay informed, you may want to start "watching" that repo (or watching releases from that repo). |
Yes, I know that the non-PHP tokenizers are going away in version 4.0. Meanwhile, the 3.x release line has a bug which can be fixed.
Description
While working with
phpcbf
, I noticed that some LESS files (which are parsed as CSS due to the specific ruleset being used) had unexpected content injected into them./* file: test.less */ // /** // * this is a comment // * this is also a comment // */
(Note the extra trailing newline at the end of the file.)
phpcs --basepath=. -s --standard=Squiz --sniffs=Squiz.WhiteSpace.SuperfluousWhitespace --extensions=less/CSS test.less
After running
phpcbf
(with the same flags as above), I get a file with this content:(Note the extra newline at the end of the file has been fixed.)
Suggested changelog entry
Fixed bug in CSS tokenizer
Types of changes
PR checklist