changcheng / wro4j

Automatically exported from code.google.com/p/wro4j
0 stars 0 forks source link

CssMin preprocessor fails when CSS contains nested braces #504

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Use a CSS that contains nested braces, e.g.
@media print {
    a[href]:after { content: " (" attr(href) ")"; }
}
2. Configure CssMin as a preprocessor
3. Boom!

What is the expected output? What do you see instead?
> Produces corrupted CSS, result may vary according to the actual count of 
nested elements. See below for details.

What version of the product are you using? On what operating system?
> Wro4j 1.4.7

Please provide any additional information below.
> See ro.isdc.wro.model.resource.processor.support.CSSMin.java
Processor split stream in selector using a simple closing curly brace detection.

Using previous example:
@media print {
    a[href]:after { content: " (" attr(href) ")"; }
}
buffer will detect new selector on '@media', but will try to close it on first 
'}'. Selector constructor will then have an unbalanced '@media 
print{a[href]:after{content:"("attr(href)")";}' input and will try to split it 
presuming there will be only one '{'. Crash silently on first nested element.

If more than one selector is nested in a '@media' tag, parsing will continue on 
the second nested element. All nested selector but the first will be included 
in minified CSS, but without media consideration.

Fix proposal:
- handle nested selectors in media tag, using leading '@' character recognition 
for example;
- see if there is no other special case of nested braces;
- provide actual information of 'new Selector()' crash on catch Exception

Original issue reported on code.google.com by leri...@gmail.com on 8 Aug 2012 at 7:46

GoogleCodeExporter commented 9 years ago

Original comment by alex.obj...@gmail.com on 8 Aug 2012 at 7:47

GoogleCodeExporter commented 9 years ago
Another example: 
@-keyframes pop{
    0% { -transform: scale(1); }
    33% { -transform: scale(1.1); }
    100% { -transform: scale(1); }
}

@-moz-keyframes pop{
    0% { -moz-transform: scale(1); }
    33% { -moz-transform: scale(1.1); }
    100% { -moz-transform: scale(1); }
}
@-webkit-keyframes pop{
    0% { -webkit-transform: scale(1); }
    33% { -webkit-transform: scale(1.1); }
    100% { -webkit-transform: scale(1); }
}

@-o-keyframes pop{
    0% { -o-transform: scale(1); }
    33% { -o-transform: scale(1.1); }
    100% { -o-transform: scale(1); }
}

Original comment by marvin.l...@gmail.com on 2 Oct 2012 at 3:20