zmoazeni/csscss

Problem parsing inline base64 encoded images

Closed this issue · 14 comments

.test {
background-image:url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAACECAYAAABRaEHiAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAHRJREFUeNqkUjESwCAIw+T/X/UHansdkLTQDnXgCAHNEW2tZbDz/Aq994bzqoY5Z8wEwiEcmmfwiRK+EGOMTVBrtz4mY9kEAyz6+E3sJ7MWBs1PaUy1lHLLmgTqElltNxLiINTBbWi0Vj5DZC9CaqZEOwQYAPhxY/7527NfAAAAAElFTkSuQmCC);
}

gives

Had a problem parsing the css at line: 1, column: 1
Failed to match sequence (SPACE? blocks:((COMMENT / NESTED_RULESET / RULESET){1, }) SPACE?) at line 1 char 1.
- Expected at least 1 of COMMENT / NESTED_RULESET / RULESET at line 1 char 1. - Expected one of [COMMENT, NESTED_RULESET, RULESET] at line 1 char 1.
|- Failed to match sequence (SPACE? '/' (!'/' .){0, } '_/' SPACE?) at line 1 char 1.
| - Expected "/_", but got ".t" at line 1 char 1. |- Failed to match sequence ('@' [^{}]{1, } '{' (COMMENT / RULESET){0, } '}' SPACE?) at line 1 char 1. | - Expected "@", but got "." at line 1 char 1.
\- Failed to match sequence (selector:([^{}]{1, }) '{' SPACE? properties:((COMMENT / ATTRIBUTE / BLANK_ATTRIBUTE){0, }) '}' SPACE?) at line 2 char 38. - Expected "}", but got "b" at line 2 char 38.

@damkraw you using v1.1.0? Support for this was a recent change.

Yes

csscss -V
csscss 1.1.0

Right on thanks. @damkraw looks like we missed some stuff in the parser

Ahhhh, it looks like the ; may be getting caught in the attribute rule. The URL and data test are testing in isolation so they didn't hit this. I imagine that ; should be ignored if it is inside a url() or quotes.

@carsonmcdonald (Funny, I was just looking at this now) I'm not sure. I'm seeing this fail in the common_test

@parser.url.must_parse "url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAACECAYAAABRaEHiAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAAHRJREFUeNqkUjESwCAIw+T/X/UHansdkLTQDnXgCAHNEW2tZbDz/Aq994bzqoY5Z8wEwiEcmmfwiRK+EGOMTVBrtz4mY9kEAyz6+E3sJ7MWBs1PaUy1lHLLmgTqElltNxLiINTBbWi0Vj5DZC9CaqZEOwQYAPhxY/7527NfAAAAAElFTkSuQmCC)"

@carsonmcdonald got it:

      rule(:url) {
        stri("url") >> parens do
          (any_quoted { http } >> space?) |
          (any_quoted { data } >> space?) |
          data | http
        end
      }

This is fixed in master and will go out in the next release.

@zmoazeni yep, I was trying to understand why it needed data in front of http. I think you need to reopen, it still can't parse this when it is part of a full attribute.

Yep, you're right.

@zmoazeni yep, it will need to ignore ; if it is inside url() or quotes I think.

I think I need to bust out a dynamic matcher and do a look behind.

Ok, all set in master.

Released in v1.2.0