Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 3.7.2

Bug #19361 CSS tokenzier generates errors when PHP embedded in CSS file
Submitted: 2012-03-30 20:32 UTC
From: christianweiss Assigned: squiz
Status: Closed Package: PHP_CodeSniffer (version 1.3.3)
PHP Version: 5.3.3 OS: debian squeez
Roadmaps: (Not assigned)    
Subscription  


 [2012-03-30 20:32 UTC] christianweiss (Christian Weiss)
Description: ------------ [exec] PHP Notice: Undefined index: bracket_closer in /usr/share/php/PHP/CodeSniffer/Tokenizers/CSS.php on line 350 [exec] PHP Stack trace: [exec] PHP 1. {main}() /usr/bin/phpcs:0 [exec] PHP 2. PHP_CodeSniffer_CLI->process() /usr/bin/phpcs:37 [exec] PHP 3. PHP_CodeSniffer->process() /usr/share/php/PHP/CodeSniffer/CLI.php:551 [exec] PHP 4. PHP_CodeSniffer->processFile() /usr/share/php/PHP/CodeSniffer.php:476 [exec] PHP 5. PHP_CodeSniffer->_processFile() /usr/share/php/PHP/CodeSniffer.php:1159 [exec] PHP 6. PHP_CodeSniffer_File->start() /usr/share/php/PHP/CodeSniffer.php:1279 [exec] PHP 7. PHP_CodeSniffer_File->_parse() /usr/share/php/PHP/CodeSniffer/File.php:382 [exec] PHP 8. PHP_CodeSniffer_File::tokenizeString() /usr/share/php/PHP/CodeSniffer/File.php:586 [exec] PHP 9. PHP_CodeSniffer_Tokenizers_CSS->processAdditional() /usr/share/php/PHP/CodeSniffer/File.php:969 [exec] PHP Notice: Undefined index: bracket_closer in /usr/share/php/PHP/CodeSniffer/Tokenizers/CSS.php on line 351 [exec] PHP Stack trace: [exec] PHP 1. {main}() /usr/bin/phpcs:0 [exec] PHP 2. PHP_CodeSniffer_CLI->process() /usr/bin/phpcs:37 [exec] PHP 3. PHP_CodeSniffer->process() /usr/share/php/PHP/CodeSniffer/CLI.php:551 [exec] PHP 4. PHP_CodeSniffer->processFile() /usr/share/php/PHP/CodeSniffer.php:476 [exec] PHP 5. PHP_CodeSniffer->_processFile() /usr/share/php/PHP/CodeSniffer.php:1159 [exec] PHP 6. PHP_CodeSniffer_File->start() /usr/share/php/PHP/CodeSniffer.php:1279 [exec] PHP 7. PHP_CodeSniffer_File->_parse() /usr/share/php/PHP/CodeSniffer/File.php:382 [exec] PHP 8. PHP_CodeSniffer_File::tokenizeString() /usr/share/php/PHP/CodeSniffer/File.php:586 [exec] PHP 9. PHP_CodeSniffer_Tokenizers_CSS->processAdditional() /usr/share/php/PHP/CodeSniffer/File.php:969 Directly from my ant output (Hudson CI)

Comments

 [2012-03-31 02:46 UTC] squiz (Greg Sherwood)
-Status: Open +Status: Feedback -Assigned To: +Assigned To: squiz
Do you happen to have the CSS file that PHPCS was running on when the error occurred? I wont be able to fix this with just a backtrace because the order of tokens is really important for this.
 [2012-04-04 13:46 UTC] christianweiss (Christian Weiss)
CSS file is: li { background:url(<?php print $staticserver; ?>images/bullet.gif) left 1px no-repeat; margin:0px; padding-left:10px; margin-bottom:5px; line-height:13px;} I know it is not usual to have css files to be executed by php but your tokenizer should be robust enought. csslint (http://csslint.net/about.html) has no trouble to tokenize it. A sniff that warns that this type of dynamic css smells should be available.
 [2012-04-04 14:00 UTC] christianweiss (Christian Weiss)
li {} should be in second line. first line is empty
 [2012-04-11 06:56 UTC] squiz (Greg Sherwood)
I cant get any tokenizer errors to be reported, but I get a errors from the sniffs, which I will look at. I don't know if they will fix the issue you have reported or not. Does the formatting of the CSS file look correct in your comment? Can you paste that single line onto line 2 of a blank CSS file and have PHPCS generate errors or is there more in the file?
 [2012-04-11 07:03 UTC] squiz (Greg Sherwood)
I think I see the problem. When PHP tokenizes this string, it see the closing tag and then stops tokenizing the rest. It wont handle PHP embedded into a CSS or JS file, where it doesn't expect there to be any PHP tags. Even though I can't get the tokenizer errors, they look the same as the sniff errors, so I think fixing this will fix your main issue.
 [2012-04-11 09:18 UTC] squiz (Greg Sherwood)
-Summary: Undefined index: bracket_closer in .../Tokenizers/CSS.php +Summary: CSS tokenzier generates errors when PHP embedded in CSS file
 [2012-04-11 09:26 UTC] squiz (Greg Sherwood)
I've committed a fix for CSS tokenizing with embedded PHP tags. Git commit is here: https://github.com/squizlabs/PHP_CodeSniffer/commit/3d66c81cc1768258099bf5d29 4d96cd1376623cd Are you able to clone the git repo and try that version to see if it works for you?
 [2012-05-11 10:42 UTC] squiz (Greg Sherwood)
-Status: Feedback +Status: Closed
Assuming it works. Please reopen if incorrect.