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

Brackets in data URI cause url reducer to parse incorrectly #633

Closed
JasonBerry opened this issue Jul 31, 2015 · 1 comment
Closed

Brackets in data URI cause url reducer to parse incorrectly #633

JasonBerry opened this issue Jul 31, 2015 · 1 comment
Labels

Comments

@JasonBerry
Copy link

This very basic SVG image:

<svg viewBox="0 0 18 18" xmlns="http://www.w3.org/2000/svg">
  <rect width="14" height="14" transform="translate(2 2)"/>
</svg>

... when whitespace is stripped and data URI'd correctly becomes:

data:image/svg+xml,%3Csvg%20viewBox%3D%220%200%2018%2018%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2214%22%20height%3D%2214%22%20transform%3D%22translate(2%202)%22%2F%3E%3C%2Fsvg%3E

When using this data URI as a background-image, CleanCSS chokes on the brackets used by the translate function and generates malformed CSS by dropping the quotes inside the url().

This happens in the byUrl function in the urls/reduce module, so specifying compatibility options like { compatibility: { properties: { urlQuotes: true } } } to CleanCSS doesn't help.

/* What should happen */
.foo {
  background-image: url("data:image/svg+xml,%3Csvg%20viewBox%3D%220%200%2018%2018%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2214%22%20height%3D%2214%22%20transform%3D%22translate(2%202)%22%2F%3E%3C%2Fsvg%3E");
}

/* What actually happens */
.foo {
  background-image: url(data:image/svg+xml,%3Csvg%20viewBox%3D%220%200%2018%2018%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%3E%3Crect%20width%3D%2214%22%20height%3D%2214%22%20transform%3D%22translate(2%202) %22%2F%3E%3C%2Fsvg%3E);
}
@jakubpawlowicz
Copy link
Collaborator

That's a bug then. If possible you can use --skip-rebase to prevent it.

jakubpawlowicz added a commit that referenced this issue Aug 5, 2015
We need to identify cases when data URI are escaped (and brackets
are not) so we can get the whole URI.
jakubpawlowicz added a commit that referenced this issue Aug 5, 2015
We need to identify cases when data URI are escaped (and brackets
are not) so we can get the whole URI.
@dosoft dosoft mentioned this issue Aug 9, 2015
jakubpawlowicz added a commit that referenced this issue Aug 9, 2015
The fix to #633 included a regression in URI processing as the
algorithm introduced should only be applied to data URIs.
jakubpawlowicz added a commit that referenced this issue Aug 9, 2015
The fix to #633 included a regression in URI processing as the
algorithm introduced should only be applied to data URIs.
jakubpawlowicz added a commit that referenced this issue Aug 9, 2015
The fix to #633 included a regression in URI processing as the
algorithm introduced should only be applied to data URIs.
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

2 participants