Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sass, different results using compressor and without, causing parsing errors #827

Closed
wjdp opened this issue Feb 15, 2017 · 11 comments · Fixed by #828
Closed

Sass, different results using compressor and without, causing parsing errors #827

wjdp opened this issue Feb 15, 2017 · 11 comments · Fixed by #828
Labels

Comments

@wjdp
Copy link

wjdp commented Feb 15, 2017

Hello, I'm running into an issue while using Bootstrap 4 alpha 6. Encountered that all CSS after the include of BS4 was ignored by the browser. Dug deeper and found parsing error of the generated css.

I'm using Django 1.8.17, Compressor 2.1.1, Sass 3.4.22

I shall document here the first parse error I found.

The error is the double quote " in stroke='rgba(0, 0, 0, 0.5")', whereas it should be stroke='rgba(0, 0, 0, 0.5)'. This causes parsing errors in the document.

Invalid Line (via dj compressor)

.navbar-light .navbar-toggler-icon {
  background-image: url("data:image/svg+xml;charset=utf8,%3Csvg viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath stroke='rgba(0, 0, 0, 0.5")' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 8h24M4 16h24M4 24h24'/%3E%3C/svg%3E"); }

Valid line (via sass direct)

.navbar-light .navbar-toggler-icon {
  background-image: url("data:image/svg+xml;charset=utf8,%3Csvg viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath stroke='rgba(0, 0, 0, 0.5)' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 8h24M4 16h24M4 24h24'/%3E%3C/svg%3E"); }

Matches with pre-compiled version.

Souce of background-image

$navbar-light-toggler-bg: str-replace(url("data:image/svg+xml;charset=utf8,%3Csvg viewBox='0 0 32 32' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath stroke='#{$navbar-light-color}' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 8h24M4 16h24M4 24h24'/%3E%3C/svg%3E"), "#", "%23") !default;

$navbar-light-color:                rgba($black,.5) !default;

$black:  #000 !default;

How we generate via dj compressor

{% compress css %}
<link rel="stylesheet" type="text/x-scss" media="screen" charset="utf-8"
    href="/static/bootstrap/scss/bootstrap.scss" />
{% endcompress %}
COMPRESS_PRECOMPILERS = (
    ('text/coffeescript', 'coffee --compile --stdio'),
    ('text/x-sass', 'sass {{infile}} {{outfile}} --load-path {}'.format(LIB_PATH)),
    ('text/x-scss', 'sass --scss {{infile}} {{outfile}} --load-path {}'.format(LIB_PATH)),
)
@karyon karyon added the bug label Feb 15, 2017
@karyon
Copy link
Contributor

karyon commented Feb 15, 2017

looks pretty bad. any help fixing this would be appreciated, i'll likely not have the time for the coming weeks.

@wjdp
Copy link
Author

wjdp commented Feb 15, 2017

I'll have a go. I'm not familiar with your codebase so any pointers on where to start / any hunches would be very valuable.

@carltongibson
Copy link
Contributor

A couple of thoughts:

  • Does this occur with COMPRESS_ENABLED = False?
  • Can you double check that the Sass version is the same? (Sorry about this one but in theory all compressor is doing is handing off the input to Sass to be processed — obviously something is going on but I want to rule this out.)

@wjdp
Copy link
Author

wjdp commented Feb 15, 2017

@carltongibson:

  • Already running with COMPRESS_ENABLED = False, same result observed with setting it True.
  • This is how I'm checking sass version. Running the server in that environment
$ sass -v 
Sass 3.4.22 (Selective Steve)

I have tried including either sass version or a pre-built bootstrap.css file in a compressor block followed by a file just containing a body background:green as a checklight for valid/parseable CSS. I'm getting 'green' for the pre-built .css version, but not for .sass—where compressor builds bootstrap.

@carltongibson
Copy link
Contributor

@wjdp OK Thanks. Hmmm.

In that case can I suggest putting a breakpoint in Compressor.precompile? Firstly is content passed in correctly?

Then in hunks() is the value returned from the precompiler correct?

@karyon
Copy link
Contributor

karyon commented Feb 16, 2017

i'm looking into this right now. the problem is the same as #764. the CssAbsoluteFilter uses r'url\(([^\)]+)\)' to match URLs, and therefore stops at the first closing parenthesis. since regex are not capable of dealing with an arbitrary number of nested parenthesis, i see three options:

  1. deal with exactly one level of nested parenthesis because that ought to be enough for anybody
  2. do it properly with more intelligent matching logic
  3. use some library to parse the css.

i don't want to spend much time on this and am looking into option 1, if anyone wants to create a more robust solution, i'd be glad to review that.

@karyon
Copy link
Contributor

karyon commented Feb 16, 2017

proposed fix in #828. it does not actually handle nested parenthesis at all, it just expects closing quotes if there are opening ones (so url("data:...stroke='rgba(0, 0, 0, 0.5) wont match) and, to be safe, data-uris are ignored altogether.

@carltongibson
Copy link
Contributor

@wjdp could you give #828 a try? It should do what you need but a test run on your part would be a good confirmation.

@wjdp
Copy link
Author

wjdp commented Feb 16, 2017

Shall do

@wjdp
Copy link
Author

wjdp commented Feb 16, 2017

@carltongibson Can confirm that PR has fixed this issue for me. Thank you @karyon for your very quick work! 😄

@carltongibson
Copy link
Contributor

Awesome 👏🏽 thanks for the follow up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants