roborourke/wp-less

Possibility to abort silently with "wrong" .less file name

Closed this issue · 4 comments

[function parse_stylesheet LINE 43](1. function parse_stylesheet LINE 43: if %28 ! strstr%28 $src,) ) will also return true if the filename is for e.g. sense.less.php and therefore fail silently.):

if ( ! strstr( $src, '.less' ) ) will also return true if the filename is for e.g. sense.less.php and therefore fail silently without any user feedback...

I think I made the decision to do it that way because you might want to output some less generated by php. I got the idea from the way ruby and rails allows you append file extensions and it runs the files through the processors in that order eg. style.css.scss.erb etc...

I think what's needed is to check the file outputs valid LESS.

What do you think to that approach? Can you think of any gotchas?

Thinking loud

For the general test, I'd go with pathinfo() -> ['extension']. You could also do some explode( '.', $filename ); and check for the existance of .php in the last index. Or leave what you currently got and just add the pathinfo check, that lets pass the .php extension if .less.php is also found (using strstr).

Here we go (not tested)...

$path_bits = pathinfo( $src );
if ( 
    ! in_array( $path_bits['extension'], array( 'php', 'less' ) )
    AND ! strstr( $src, '.less' )
)
    return;

..but should work.

Ok - had some time to work on this. I found the best approach to use a very explicit preg_match(). Unfortunately using pathinfo() leaves the query string attached to the extension so it was simpler to do it the way it is now.

Thanks for bringing up these problems, as always very useful :)