Skip to content

Inline source map loading fails when data uri contains comma #86

@jerome-rdlv

Description

@jerome-rdlv

I’m using Dart Sass cli to generate CSS with embeded sourcemap. The resulting sourcemap is percent-encoded with encodeURI, not encodeURIComponent and thus contains commas.

Because of this, the stripComment function fails by returning only the last segment of text after the last comma, which breaks sourcemap integrity and is not valid JSON.

I briefly search the source map spec to see if maybe it was a non-compliance on Dart Sass side, but I couldn’t found a clear answer:

Source maps are linked through URLs as defined in WHATWG URL; in particular, characters outside the set permitted to appear in URIs shall be percent-encoded and it may be a data URI. Using a data URI along with sourcesContent allows for a completely self-contained source map. source

And according to Wikipedia, it seams that commas are allowed in clear:

data:text/plain;charset=UTF-8;page=21,the%20data:1234,5678

A simple change in stripComment would allow to drop content up to the first comma only, and return the rest.

I’ll submit a pull request with that change, and corresponding tests, in case it is acceptable for you.
But I’d be glad to have your opinion on this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions