cssmin icon indicating copy to clipboard operation
cssmin copied to clipboard

Stripping spaces that are necessary

Open tdreyno opened this issue 14 years ago • 10 comments

I've got a bug report in a my project against cssmin: https://github.com/middleman/middleman/issues/254

Basically:

@media handheld, only screen and (device-width: 768px), (device-width: 800px)

will strip the space between and and ( and get turned into this invalid css:

@media handheld, only screen and(device-width: 768px), (device-width: 800px)

tdreyno avatar Jan 31 '12 17:01 tdreyno

i have also came across this problem :-(

mcgoooo avatar Feb 07 '12 15:02 mcgoooo

I was interested in tackling this bug, but then saw that there aren't any tests. We should totally write some of those! :)

dwo avatar Feb 07 '12 22:02 dwo

Totally! I don't use cssmin myself anymore so I haven't touched it in a while, but pull requests are more than welcome.

rgrove avatar Feb 08 '12 07:02 rgrove

What do you use these days, out of interest? We considered switching to another minification engine in AssetHat to get around this.

dwo avatar Feb 08 '12 10:02 dwo

consider https://github.com/sprsquish/rainpress

stereobooster avatar Feb 08 '12 10:02 stereobooster

Rainpress removes a different space (lol):

@media handheld,only screen and (device-width:768px)

tdreyno avatar Feb 08 '12 16:02 tdreyno

I use YUI Compressor these days. The compression routines in cssmin.rb are based on an early compressor called cssmin.js that was written by Isaac Schlueter, and which also later became the basis for the CSS compression routines in YUI Compressor, so they're very similar. The main difference is that YUI Compressor is more actively maintained and treats media queries correctly, although since it's not Ruby it's obviously harder to integrate into Ruby projects.

In any case, I'd be happy to accept pull requests with fixes or tests, and I'll probably get around to fixing this myself eventually if no one else contributes a patch, but it's not high on my todo list since I don't personally need it.

rgrove avatar Feb 08 '12 18:02 rgrove

WRT this problem, it looks like YUI just adds the space back in after stripping: https://github.com/yui/yuicompressor/blob/master/src/com/yahoo/platform/yui/compressor/CssCompressor.java#L234-236

@rgrove if i were to write a test for this case, is there a framework you'd prefer over rspec?

dwo avatar Mar 28 '12 15:03 dwo

@dwo MiniTest is probably what I'd go with these days. Thanks for asking!

rgrove avatar Mar 29 '12 09:03 rgrove

my own trial css_press. Pure ruby, real css parser

stereobooster avatar Apr 15 '12 20:04 stereobooster