Migrate from GitHub to SourceForge with this tool. Check out all of SourceForge's recent improvements.
Close

#62 Does not support star hack of IE7

0.9.21
closed
RBRi
None
1
2017-01-08
2016-04-19
Philip John
No

Discussion

  • Philip John

    Philip John - 2016-04-19
     
    Last edit: Philip John 2016-04-19
    • Anonymous

      Anonymous - 2018-04-12
      Post awaiting moderation.
  • Philip John

    Philip John - 2016-04-19

    The parser does not support star hack property of IE 7.

    div {
    *display: inline;
    }

    The above section in CSS throws the following error .
    Error in declaration. '' is not allowed as first char of a property.

     
    Last edit: Philip John 2016-04-19
  • RBRi

    RBRi - 2016-05-14

    Hi,
    what do you expect in this case?
    All modern browsers are ignoring this rule also.

     
  • RBRi

    RBRi - 2016-05-14
    • status: open --> pending
    • assigned_to: RBRi
     
  • RBRi

    RBRi - 2016-05-23
    • Group: 0.9.19 --> 0.9.20
     
  • Adam Gabryś

    Adam Gabryś - 2016-05-27

    Hi,
    A lof of developers must support old browsers (e.g. banking applications). I think it will be nice if the parser will treat attributes with star prefix as standard attributes.

    Example:

    rule {
        display: "this value is not supported by IE7";
        new-browsers-attribute1: "this attribute is ignored by IE7";
        new-browsers-attribute2: "this attribute is ignored by IE7";
        *display: "old stuff for IE7 compatibility";
    }
    

    Regards

     
    Last edit: Adam Gabryś 2016-05-27
  • RBRi

    RBRi - 2016-07-23
    • Group: 0.9.20 --> 0.9.21
     
  • RBRi

    RBRi - 2016-12-29

    Hi Philip/Adam,
    sorry for getting back that late. Is this still an issue for you?

     
    Last edit: RBRi 2016-12-29
  • Adam Gabryś

    Adam Gabryś - 2016-12-29

    Hi,
    This issue was reported by Philip to my tool responsible for spliting CSS stylesheets to smaller files: https://github.com/gabrysbiz/css-splitter-maven-plugin/issues/8

    For me it is not a problem (I don't develop any project which operates on CSS files) , but it will be nice if my tool can support it :-)

     
  • RBRi

    RBRi - 2016-12-30

    Hi Adam,
    thanks for the fast answer. Hope i got your point now.
    There is a new snapshot available that supports a switch to enable start hack support. Hope that does the job for you.

     
    Last edit: RBRi 2016-12-30
  • Adam Gabryś

    Adam Gabryś - 2016-12-30

    Hi,
    Unfortunatelly it does not work. I upgraded parser to 0.9.21-SNAPSHOT and tried to parse:

    .outlineClr {
        outline: 0;
        outline-style: none;
        outline-width: 0;
        *display: inline;
    }
    

    The parser threw exception:

    Caused by: org.w3c.css.sac.CSSParseException: Error in declaration. '*' is not allowed as first char of a property.
        at com.steadystate.css.parser.AbstractSACParser.toCSSParseException(AbstractSACParser.java:264)
        at com.steadystate.css.parser.SACParserCSS3.declaration(SACParserCSS3.java:2216)
        at com.steadystate.css.parser.SACParserCSS3.styleDeclaration(SACParserCSS3.java:2142)
        at com.steadystate.css.parser.SACParserCSS3.styleRule(SACParserCSS3.java:1347)
        at com.steadystate.css.parser.SACParserCSS3.styleSheetRuleList(SACParserCSS3.java:174)
        at com.steadystate.css.parser.SACParserCSS3.styleSheet(SACParserCSS3.java:56)
        at com.steadystate.css.parser.AbstractSACParser.parseStyleSheet(AbstractSACParser.java:282)
        at com.steadystate.css.parser.SACParserCSS3.parseStyleSheet(SACParserCSS3.java:31)
        at com.steadystate.css.parser.CSSOMParser.parseStyleSheet(CSSOMParser.java:136)
        at biz.gabrys.maven.plugins.css.splitter.steadystate.SteadyStateParser.parse(SteadyStateParser.java:45)
        ... 27 more
    
     
  • Adam Gabryś

    Adam Gabryś - 2016-12-30

    Sorry, I forgot to set setIeStarHackAccepted property.

    I see an entry in logs:
    [WARNING] [5:5] Error in declaration. '*' is not allowed as first char of a property.
    Can you stop calling ErrorHandler#warning when this property is enabled?

    And last thing ;-) Is there any chance that you will provide a common interface for all parsers? Now I use this code to create parsers:

    class NativeParserFactory {
    
        private static final Map<Standard, Class<? extends Parser>> PARSERS_BY_CSS_STANDARD;
    
        static {
            PARSERS_BY_CSS_STANDARD = new ConcurrentHashMap<Standard, Class<? extends Parser>>();
            PARSERS_BY_CSS_STANDARD.put(Standard.VERSION_1_0, SACParserCSS1.class);
            PARSERS_BY_CSS_STANDARD.put(Standard.VERSION_2_0, SACParserCSS2.class);
            PARSERS_BY_CSS_STANDARD.put(Standard.VERSION_2_1, SACParserCSS21.class);
            PARSERS_BY_CSS_STANDARD.put(Standard.VERSION_3_0, SACParserCSS3.class);
        }
    
        Parser create(final Standard standard) {
            try {
                return PARSERS_BY_CSS_STANDARD.get(standard).newInstance();
            } catch (final InstantiationException e) {
                throw new IllegalStateException(e);
            } catch (final IllegalAccessException e) {
                throw new IllegalStateException(e);
            }
        }
    }
    

    I want to set star hack property, so I have to do something like this:

    class NativeParserFactory {
    
        Parser create(final Standard standard) {
            if (Standard.VERSION_1_0 == standard) {
                final SACParserCSS1 parser = new SACParserCSS1();
                parser.setIeStarHackAccepted(true);
                return parser;
            }
    
            if (Standard.VERSION_2_0 == standard) {
                final SACParserCSS2 parser = new SACParserCSS2();
                parser.setIeStarHackAccepted(true);
                return parser;
            }
    
            if (Standard.VERSION_2_1 == standard) {
                final SACParserCSS21 parser = new SACParserCSS21();
                parser.setIeStarHackAccepted(true);
                return parser;
            }
    
            if (Standard.VERSION_3_0 == standard) {
                final SACParserCSS3 parser = new SACParserCSS3();
                parser.setIeStarHackAccepted(true);
                return parser;
            }
    
            return null;
        }
    }
    

    I tried to use AbstractSACParser (which defines that property) but it's visibiliti is equal to package

    Code like this will be very nice:

    Parser create(final Standard standard) {
        try {
            final SACParser parser = PARSERS_BY_CSS_STANDARD.get(standard).newInstance();
            parser.setIeStarHackAccepted(true);
            return parser;
        } catch (final InstantiationException e) {
            throw new IllegalStateException(e);
        } catch (final IllegalAccessException e) {
            throw new IllegalStateException(e);
        }
    }
    
     
  • RBRi

    RBRi - 2016-12-31

    Ok, have added the SACParser interface as extension of Parser and as the interface implemented by AbstractSACParser.

    Regarding the waring i think it it ok to send out the warning for two reasons
    1. it is really an invalid css
    2. because cssparser stores the star as part of the property name the user has to take care of this

    What is your problem with the warning?

     
  • Adam Gabryś

    Adam Gabryś - 2016-12-31

    I upgraded CSS Parser the latest SNAPSHOT. The SACParser exists but it's not visible (not public). In addition it seems to me that AbstractSACParser still implements Parser instead of SACParser.

    About warning, I think that the following strategy would be good:
    if user didn't enable hack support, then the error should occur - because CSS is invalid
    if user enabled hack support, then no warning should be displayed - because user knows that CSS contains invalid code (the reason why user enabled hack support). For now user will see a lot of warnings which will be ignored, because user wants that code. For me a warning is something what I should fix, not ignore.

    What do you think?

     
    Last edit: Adam Gabryś 2016-12-31
  • RBRi

    RBRi - 2016-12-31

    The SACParser interface is now public, SNAPSHOT is updated; sorry.

     
  • RBRi

    RBRi - 2016-12-31

    Ok, warning gone, snapshot is new.

     
  • Comment has been marked as spam. 
    Undo

    You can see all pending comments posted by this user  here

    Anonymous

    Anonymous - 2016-12-31

    It works! Thank you very much for your work.

    When do you plan to release 0.9.21?

     
  • RBRi

    RBRi - 2016-12-31

    Sorry but there are no plans for a release this year :-)
    For the release i like to add the calc support - if possible the release will be available in Jan 2017,

     
  • RBRi

    RBRi - 2016-12-31
    • status: pending --> closed
     
  • Comment has been marked as spam. 
    Undo

    You can see all pending comments posted by this user  here

    Anonymous

    Anonymous - 2016-12-31

    No problem :-) I was just curious.

    Happy new year.

     
  • Comment has been marked as spam. 
    Undo

    You can see all pending comments posted by this user  here

    Anonymous

    Anonymous - 2016-12-31

    Sorry, one more thing.

    I wrote some tests and I realized that star hack works only for CSS21 and CSS3 parsers. For CSS1 and CSS2 it throws exception:

    Invalid token "*". Was expecting one of: <S>, <IDENT>, "}", ";"
    

    Tested CSS:

    div {
     width: 0;
     *width: 0;
     height: 0;
    }
    
     
  • Adam Gabryś

    Adam Gabryś - 2017-01-08

    Ok, I see in changelog (http://cssparser.sourceforge.net/changes-report.html#a0.9.21) that it will work only for CSS 2.1 and 3.0. So I will adjust my code.

    Best regards

     

Anonymous
Anonymous

Cancel  Add attachments