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

Single quotation marks inside double-quoted strings are removed #763

Closed
chris-morgan opened this issue Apr 26, 2016 · 4 comments
Closed
Labels
Milestone

Comments

@chris-morgan
Copy link

Example:

:root {
    background: url("data:image/svg+xml,%3csvg%20xmlns%3d'http://www.w3.org/2000/svg'/%3e");
}

This is cleaned to:

:root{background:url(data:image/svg+xml,%3csvg%20xmlns%3dhttp://www.w3.org/2000/svg/%3e)}

This is glaringly incorrect: it was fine to remove the double quotation marks, but definitely not to scrap the single quotation marks! The change breaks the embedded SVG.

If the data: URI contains ) or   it will leave all the quotes in, but that’s not a desirable solution.

As it stands, the workaround is to replace each ' with %27.

@jakubpawlowicz
Copy link
Collaborator

Thanks @chris-morgan for bringing this up. It should definitely keep single quotes. Btw, what's the method you escape inlined SVG?

@chris-morgan
Copy link
Author

I have a habit of hand-writing SVG. Even hand-writing URL-encoded SVG.

The thing is that most of the encoding that something like encodeURIComponent will do isn’t necessary, and turns one byte into three for no purpose. (Sure, gzip will reclaim most of the delta, but meh.) Most browsers actually need practically no escaping—only making sure the quotes match and that # becomes %23; it’s just IE that is a little stricter (closer to the what the specs say, though even it is still more liberal than the spec). I just checked on IE 11 and it turns out that I can now skip encoding   and = as well, leaving in most cases only <%3C, >%3E and #%23. (IE9 was stricter, needing uppercase %-escapes and a few more characters, but I normally don’t care about IE9.) Regular expressions help to replace those few.

SVG minimisation beyond what tools like SVGO do is a bit of a hobby of mine. I know far more about it all than is good for me.

@jakubpawlowicz
Copy link
Collaborator

Thanks for more details @chris-morgan. Let's fix it.

@jakubpawlowicz jakubpawlowicz added this to the 3.4.13 milestone May 2, 2016
jakubpawlowicz added a commit that referenced this issue May 30, 2016
Quotes inside data URI SVG can be unescaped and we should handle
such cases correctly by leaving quoting in place.
@jakubpawlowicz
Copy link
Collaborator

Fixed in 3.4.14.

silverwind pushed a commit to silverwind/clean-css that referenced this issue Sep 25, 2016
Quotes inside data URI SVG can be unescaped and we should handle
such cases correctly by leaving quoting in place.
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