Skip to content
This repository was archived by the owner on Aug 27, 2026. It is now read-only.
This repository was archived by the owner on Aug 27, 2026. It is now read-only.

convertToAbsoluteUrls makes the URL prefix prepended to SVG data URLs if they contain comments #214

Closed

Description

@mgol

Do you want to request a feature or report a bug?

Bug.

What is the current behavior?
Data URLs defining SVGs with HTML comments get a URL prefix prepended, breaking the rule.

If the current behavior is a bug, please provide the steps to reproduce.

For the following input:

.test {
    background-image: url('data:image/svg+xml,%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-8%22%3F%3E%0A%3C!--%20Comment)%20--%3E%0A%3Csvg%3E%3C%2Fsvg%3E%0A');
}

Using the style-loader with the default convertToAbsoluteUrls: true and source maps enabled gets converted to:

.test {
  background-image: url("https://localhost:8000/my-current-path/'data:image/svg+xml,%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-8%22%3F%3E%0A%3C!--%20Comment")%20--%3E%0A%3Csvg%3E%3C%2Fsvg%3E%0A');
}

Let me know if that's not enough to reproduce on your end.

What is the expected behavior?
Nothing should get prepended.

If this is a feature request, what is motivation or use case for changing the behavior?
N/A

Please mention other relevant information such as your webpack version, Node.js version and Operating System.
macOS 10.12.4 (16E195), Node.js 6.10.2, Webpack 2.3.3, style-loader 0.16.1

Related: #195

Activity

  1. alexander-akait commented on Apr 19, 2017

    @alexander-akait
    Member

    @mgol Example contradict specification, your should use data:image/svg+xml;charset=utf-8,%3C!--%20Comment%20--%3E%3Csvg%3E%3C%2Fsvg%3E https://drafts.csswg.org/css-values-3/#urls.
    I don't see in spec section allowing to use raw data without data

  2. alexander-akait commented on Apr 19, 2017

    @alexander-akait
    Member

    @mgol can you provide use case and how '%3C!--%20Comment%20--%3E%3Csvg%3E%3C%2Fsvg%3E' in url without data, maybe create minimal reproduced test repo

  3. mgol commented on Apr 19, 2017

    @mgol
    ContributorAuthor

    I'm sorry, when I was creating a minimal example I cut out too much. Please take another look, I edited the post.

    Note that I can't specify the charset as that breaks IE 11 for some reason; UTF-8 is a default anyway, though.

  4. alexander-akait commented on Apr 19, 2017

    @alexander-akait
    Member

    @mgol weird, bootstrap v4 use charset=utf8 https://github.com/twbs/bootstrap/blob/v4-dev/scss/_variables.scss#L467 and they support IE 10-11, also they tests are passed 🤔

  5. alexander-akait commented on Apr 19, 2017

    @alexander-akait
    Member

    @mgol anyway your url is wrong, data:image/svg+xml,%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-8%22%3F%3E%0A%3C!--%20Comment)%20--%3E%0A%3Csvg%3E%3C%2Fsvg%3E%0A have ), see spec https://drafts.csswg.org/css-syntax-3/#url-token-diagram:
    not " ' ( ) \ ws or non-printable

  6. alexander-akait commented on Apr 19, 2017

    @alexander-akait
    Member

    /cc @michael-ciniawsky I think that it is won't fix, because comments in svg can contain any characters and it is can break url in css.

    Maybe we can remove comments in url-loader for svg files?

  7. michael-ciniawsky commented on Apr 20, 2017

    @michael-ciniawsky
    Contributor

    @evilebottnawi Could you please open an issue in url-loader, so we can keep track of/triage that ? :)

  8. alexander-akait commented on Apr 20, 2017

    @alexander-akait
    Member

    @michael-ciniawsky sorry i don't right, url-loader always use decode data because it is base64, we can do this in css-loader, i do PR

  9. mgol commented on Apr 20, 2017

    @mgol
    ContributorAuthor

    @evilebottnawi

    @mgol anyway your url is wrong, data:image/svg+xml,%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22utf-8%22%3F%3E%0A%3C!--%20Comment)%20--%3E%0A%3Csvg%3E%3C%2Fsvg%3E%0A have ), see spec https://drafts.csswg.org/css-syntax-3/#url-token-diagram:
    not " ' ( ) \ ws or non-printable

    I see, good to know. No browser follows that restriction, though as this data URL worked everywhere for me.

  10. alexander-akait commented on Apr 20, 2017

    @alexander-akait
    Member

    @mgol on the idea that this is where it works, not the best practice, for this purpose there are specifications, to support non-standard behavior is not a good idea, but I have an idea how it can still be fixed anyway.

  11. mgol commented on Apr 20, 2017

    @mgol
    ContributorAuthor

    Yes, I understand, I've already removed such usage from my code. My point is Web standards have recently tried to match reality as much as possible so if every single major browser behaves differently to the spec (and consistent with each other) then maybe the spec should get an update.

  12. alexander-akait commented on Apr 20, 2017

    @alexander-akait
    Member

    @mgol maybe, let's this will leave the creators of the browser and specifications, we have a lot of work here 😄

  13. alexander-akait commented on Jun 29, 2017

    @alexander-akait
    Member

    @mgol just confirm, try to update style-loader and css-loader to latest and check bug exists

  14. added this to the 1.0.0 milestone on Nov 8, 2017
  15. alexander-akait commented on Dec 7, 2017

    @alexander-akait
    Member

    Seems bug already fixed https://github.com/webpack-contrib/style-loader/blob/master/lib/urls.js#L57 and https://github.com/webpack-contrib/style-loader/blob/master/lib/urls.js#L65, in style-loader we have invalid regex to parse url.

    @michael-ciniawsky unfortunately, it will not test right now, because jsdom don't have implement createObjectURL and revokeObjectURL.

    I close the issue, if someone have problem please update to latest version style-loader. Also feel free to comment here if you will get problem again. Thank everyone.

  16. removed their assignment
    on Dec 7, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions