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

xml parsing error in svg image url after compression #910

Closed
hiamandeep opened this issue May 26, 2018 · 4 comments
Closed

xml parsing error in svg image url after compression #910

hiamandeep opened this issue May 26, 2018 · 4 comments
Labels

Comments

@hiamandeep
Copy link

hiamandeep commented May 26, 2018

I have compressed bootstrap.min.js using django_compressor

the navbar collapse icon is not rendering due to XML parsing error.
I am using bootstrap4, I didn't face such problem with bootstrap3

i saw the difference using inspect element in firefox

No error (without compression)

.navbar-dark .navbar-toggler-icon {
	background-image: url("data:image/svg+xml;charset=utf8,%3Csvg viewBox='0 0 30 30' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath stroke='rgba(255, 255, 255, 0.5)' stroke-width='2' stroke-linecap='round' stroke-miterlimit='10' d='M4 7h22M4 15h22M4 23h22'/%3E%3C/svg%3E")
}

this gives XML error (after compression)

.navbar-dark .navbar-toggler-icon {
	background-image: url("data:image/svg+xml;charset=utf8,%3CsvgviewBox='003030'xmlns='http://www.w3.org/2000/svg'%3E%3Cpathstroke='rgba(255,255,255,0.5)'stroke-width='2'stroke-linecap='round'stroke-miterlimit='10'd='M47h22M415h22M423h22'/%3E%3C/svg%3E")
}
@vdboor
Copy link

vdboor commented Jun 2, 2018

I can confirm this is still happening, despite the changes in #828

I'm using Django 2.0, Python 3.6, django-compressor 2.2, Bootstrap 4.1.1

The problem is caused by CSSMinFilter

@karyon karyon added the bug label Apr 7, 2019
@jsma
Copy link
Contributor

jsma commented Jun 10, 2019

Borrowing from a workaround for csscompressor, I added a custom filter to wrap rcssmin (replace CSSMinFilter in settings.COMPRESS_FILTERS with the dotted path string to this filter and change the callback path). This will replace spaces in data URLs with "%20" before handing off to rcssmin which prevents rcssmin from mangling the URLs.

def compress(css, **kwargs):
    capture_svg = re.compile(r'url\("(data:image/svg.*?svg%3[Ee])\"\)')
    data_urls = re.findall(capture_svg, css)
    for data_url in data_urls:
        css = css.replace(data_url, data_url.replace(' ', '%20'))
    css = cssmin(css, **kwargs)
    return css


class CSSMinFilter(CallbackOutputFilter):
    callback = 'myapp.core.utils.compress'

This issue has also been reported to rcssmin.

FYI, this issue appears to be a duplicate of #878.

@jsma
Copy link
Contributor

jsma commented Apr 29, 2022

Can this be closed now that rccsmin==1.1.0 is the default CSS filter and the upstream issue has been fixed?

@diox
Copy link
Member

diox commented Apr 29, 2022

Yes, thanks for flagging.

@diox diox closed this as completed Apr 29, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants