oyejorge / less.php

less.js ported to PHP.
http://lessphp.typesettercms.com
Apache License 2.0
656 stars 2 forks source link

Fatal Error on MS filter expression #220

Open splitbrain opened 9 years ago

splitbrain commented 9 years ago

The parser is crashing with a fatal error on certain Microsoft filter statements. The interesting thing is that this seems to be white space related.

Here's a test case:

<?php                                                                                                                   
require_once('vendor/autoload.php');                                                                                    

echo "---- first test ----------------\n";                                                                              
$parser = new Less_Parser();                                                                                            
$parser->parse( '                                                                                                       
div {                                                                                                                   
  opacity: 0.5;                                                                                                         
  filter: alpha(opacity=50);                                                                                            
}                                                                                                                       
' );                                                                                                                    
echo $parser->getCss();                                                                                                 

echo "---- second test ----------------\n";                                                                             
$parser = new Less_Parser();                                                                                            
$parser->parse( '                                                                                                       
div {                                                                                                                   
  opacity: 0.5;                                                                                                         
  filter: alpha(opacity = 50);                                                                                          
}                                                                                                                       
' );                                                                                                                    
echo $parser->getCss(); 

It creates the following output:

---- first test ----------------
div {
  opacity: 0.5;
  filter: alpha(opacity=50);
}
---- second test ----------------
PHP Fatal error:  Call to undefined method Less_Tree_Assignment::toHSL() in /home/andi/temp/2015-05-15/test/vendor/oyejorge/less.php/lib/Less/Functions.php on line 191

As you can see, the first input parses fine, the second crashes the parser.

This might be related to #210 and #198. I'd be fine with a sensible error message being thrown if the syntax is bad, but a fatal error is problematic.

oyejorge commented 9 years ago

Gonna check to see if this was fixed in less.js 1.7.1

oyejorge commented 9 years ago

Dang, it appears to be a problem through 1.7.5

seven-phases-max commented 9 years ago

Less parser just can't tolerate all possible vendor extensions syntax. It's OK to pass alpha(opacity=50); in since it's the only syntax mentioned syntax in the MS docs... and if you feel like whitespace is something that must be there, just write it in old good escaping way: alpha(~"opacity = 50");.

splitbrain commented 9 years ago

I don't care if it is supported or not. The bug is about the parser crashing with a fatal error instead of throwing a proper exception. On May 17, 2015 8:24 PM, "Max Mikhailov" notifications@github.com wrote:

Less parser just can't tolerate all possibly vendor extennsions syntax. It's OK to pass alpha(opacity=50); in since it's the only syntax mentioned syntax in the MS docs... and if you feel like whitespace is something that must be there write it in old good escaping way alpha(~"opacity = 50");.

— Reply to this email directly or view it on GitHub https://github.com/oyejorge/less.php/issues/220#issuecomment-102833180.