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

#46 colon in filter value leads to parsing error

0.9.14
closed
RBRi
None
1
2015-02-23
2014-02-15
No

Parsing a css file with content:

.test{
filter: progid:DXImageTransform.Microsoft.gradient(enabled=false);
}

leads to error:

java.lang.IllegalArgumentException: ERROR: at position <2,19> Fehler in Style-Regel. (Ungültiger Token ":". Erwartet wurde einer von: <EOF>, <S>, <NUMBER>, "inherit", <IDENT>, <STRING>, <PLUS>, <COMMA>, <HASH>, <IMPORTANT_SYM>, <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <PERCENTAGE>, <DIMENSION>, <URI>, <FUNCTION>, "}", ";", "/", "-".)
    at com.steadystate.css.parser.AbstractSACParser.toCSSParseException(AbstractSACParser.java:251)
    at com.steadystate.css.parser.SACParserCSS3.styleRule(SACParserCSS3.java:1077)
    at com.steadystate.css.parser.SACParserCSS3.styleSheetRuleList(SACParserCSS3.java:167)
    at com.steadystate.css.parser.SACParserCSS3.styleSheet(SACParserCSS3.java:53)
    at com.steadystate.css.parser.AbstractSACParser.parseStyleSheet(AbstractSACParser.java:284)
    at com.steadystate.css.parser.SACParserCSS3.parseStyleSheet(SACParserCSS3.java:23)
    at com.steadystate.css.parser.CSSOMParser.parseStyleSheet(CSSOMParser.java:146)
    at de.conterra.mapapps.js.ParsingCSSCompressor.compress(ParsingCSSCompressor.java:39)
    at de.conterra.mapapps.js.ParsingCSSCompressorTest.testFilterOptimize(ParsingCSSCompressorTest.java:42)

Test was based on version 0.9.13.

Discussion

  • RBRi

    RBRi - 2014-02-16
    • Description has changed:

    Diff:

    --- old
    +++ new
    @@ -6,6 +6,8 @@
    
     leads to error:
    +
    +~~~~
    
     java.lang.IllegalArgumentException: ERROR: at position <2,19> Fehler in Style-Regel. (Ungültiger Token ":". Erwartet wurde einer von: <EOF>, <S>, <NUMBER>, "inherit", <IDENT>, <STRING>, <PLUS>, <COMMA>, <HASH>, <IMPORTANT_SYM>, <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <PERCENTAGE>, <DIMENSION>, <URI>, <FUNCTION>, "}", ";", "/", "-".)
        at com.steadystate.css.parser.AbstractSACParser.toCSSParseException(AbstractSACParser.java:251)
    @@ -18,5 +20,6 @@
        at de.conterra.mapapps.js.ParsingCSSCompressor.compress(ParsingCSSCompressor.java:39)
        at de.conterra.mapapps.js.ParsingCSSCompressorTest.testFilterOptimize(ParsingCSSCompressorTest.java:42)
    
    +~~~~
    
     Test was based on version 0.9.13.
    
     
  • RBRi

    RBRi - 2014-02-16

    Marko,

    looks like you use the old IE6 was of defining the filter. CSSParser already supports the IE8 version.

    filter: progid:DXImageTransform.Microsoft.gradient(GradientType=0, startColorstr=#6191bf, endColorstr=#cde6f9); /* IE6 & IE7 */
    -ms-filter: "progid:DXImageTransform.Microsoft.gradient (GradientType=0, startColorstr=#6191bf, endColorstr=#cde6f9)"; /* IE8 */
    

    Thanks god IE6 is history. What is your motivation for this?

     
  • RBRi

    RBRi - 2014-02-16
    • status: open --> pending
     
  • Marko Reiprecht

    Marko Reiprecht - 2014-02-16

    I tried to parse a very large css file, which I doesn't create. I reported the problems I found during parsing this css file.
    In this file is also the new "-ms-filter" variant. I think both variants are in it because of the fact that the project is for a customer, which still want's that we support IE 7 (hope this is not for ever...).

    Maybe it is not a problem. Currently I use an error handler which fails fast. So if I use one which don't break the parsing, then I can handle it in an custom way? My goal is to collect some metadata of the css file. Count selectors, check for selector/rule duplicates. For this purpose the parsing should not fail on unexpected values and only report such things as warnings.

    By the way: Good work! I like your project and the parser is really fast.

     
  • mercury

    mercury - 2014-04-29

    This type of declaration is being used in Bootstrap, and hence is quite common.

    When parsing such a CSS file, I don't see an exception, but a warning is printed:

    Error in style rule. (Invalid token ":". Was expecting one of: <EOF>, <S>, <NUMBER>, "inherit", <IDENT>, <STRING>, <PLUS>, <COMMA>, <HASH>, <IMPORTANT_SYM>, <EMS>, <EXS>, <LENGTH_PX>, <LENGTH_CM>, <LENGTH_MM>, <LENGTH_IN>, <LENGTH_PT>, <LENGTH_PC>, <ANGLE_DEG>, <ANGLE_RAD>, <ANGLE_GRAD>, <TIME_MS>, <TIME_S>, <FREQ_HZ>, <FREQ_KHZ>, <PERCENTAGE>, <DIMENSION>, <URI>, <FUNCTION>, "}", ";", "/", "-".)
    

    Followed by:
    Ignoring the following declarations in this rule.

    My worry is the latter message: why are the following declarations ignored? Is it possible to skip to ';' and continue parsing the following declarations in the rule?

    Thanks!

     
  • RBRi

    RBRi - 2014-04-29

    Hi all,

    finally i found some time to try to fix this.
    Have uploaded a snapshot build that should be able to parse the strange MS stuff.
    Please try and report back.

     
  • mercury

    mercury - 2014-04-29

    Thanks RBRi. I confirm that there is no error or exception with the SNAPSHOT build.

    However, I haven't yet checked that the rest of the rule gets parsed or not.

     
  • mercury

    mercury - 2014-04-30

    The error message has gone, but remaining declarations in the rule are being ignored.

     
  • mercury

    mercury - 2014-04-30

    Correction: The error message is still there, and the following declarations are being ignored.

    When I tried a big file CSS file, the error messages seemed to have gone, but when I tried with a very small test case, the error message is back again.

    Here's the simpler test case:

            div {                                                                                                                                                                                 
               filter: xyz: df;
               border:2px solid green;
             }
    

    The border declaration is ignored.

     
    • RBRi

      RBRi - 2014-04-30

      Correction: The error message is still there, and the following declarations are being ignored.

      Hope you are wrong here.
      The fix did not fix the skipping of the whole rule in case of some errors (at least the missplaced ':' in your case). The fix enables the parser to deals with (and only with) the progid:DXImageTransform.Microsoft.foo syntax. So for your testcase you have to use something like:

      div { filter: progid:DXImageTransform.Microsoft.df(param); border:2px solid green; }

      In fact i added an unit test that more or less tests the same.

      So please check again. Hope this helps in your case.
      And of course if you can provide some kind of patch with a more general solution, your welcome....

       
      Last edit: RBRi 2014-04-30
  • mercury

    mercury - 2014-04-30

    Ah okay. I didn't realize that the fix was for a specific error.

    If I want to suggest a more general fix, shall I open a new bug for it? Basically, I have observed that browsers don't ignore following declarations in a rule when they encounter an error. I don't know what the stand of this project is about such behavior. On the one hand, it might complicate the parsers and encourage deviant syntax. On the other hand, it might give better compatibility with the rest of the ecosystem.

     
  • RBRi

    RBRi - 2014-04-30

    Of course you are right. I'm already trying to find a better solution, that ignores only the broken part. Let's see....

     
  • RBRi

    RBRi - 2014-05-02

    Ok, after some more fighting i have implemented another workaround for this. Now the parser treats all expressions containing a colon as error but now the skipping is improved. All following expressions inside the same declarations are parsed.

     
  • RBRi

    RBRi - 2014-05-02
    • status: pending --> closed
    • assigned_to: RBRi
     
  • mercury

    mercury - 2014-05-02

    Thanks! I tried cssparser-0.9.14-20140502.124840-3.jar and all works well.

    One minor thing, the warning is still shown: "Ignoring the following declarations in this rule." though the declarations do get parsed.

     
  • RBRi

    RBRi - 2014-05-02

    Right, snapshot is updated.

     

Anonymous
Anonymous

Cancel  Add attachments