-
-
Notifications
You must be signed in to change notification settings - Fork 601
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
Missing quotes in url() for data URIs returned from another loader #615
Comments
This is affecting us too. Looks like |
This is definitely an error on css-loaders part. At the moment, quotes are stripped unless there is a space in the url, but the rules for valid URLs are more complicated than that. To quote the spec:
I think the correct approach would be to escape the URL when injecting it by escaping and wrapping the result of the require-call. I'll try to put a pull-request together tonight. If anyone needs a temporary solution now, you can use this skeleton-loader: {
loader: 'skeleton-loader',
options: {
procedure: (content) => {
return content.replace(
/(?:\\")?" ?\+ ?require\((.+?)\) ?\+ ?"(?:\\")?/g,
'\\"" + require($1).replace(/^"/, "").replace(/"$/, "").replace(/"/g, "\\\\\\"").replace(/\\n/g, "\\\\n") + "\\"'
)
},
},
} It should be placed right after css-loader. I haven't tested other cases than my own (inline svgs with |
@kgram PR welcome |
Hi!
STR:
Using node 8.5.0:
yarn install
yarn build
dist/styles.bundle.css
Expected:
Actual
ie: Including the data URI inline in the CSS file works fine (thanks to the fix in #15), however when the resource is
url('./svg-data-uri.txt')
and so processed by another loader (which for simplicity for this testcase is just theraw-loader
) the data URI string returned by the loader isn't wrapped in quotes, so is invalid CSS.Contrast this to html-loader by inspecting
dist/index.html
, which successfully converts:...to:
Due to this issue, svg-url-loader unfortunately defaults to adding extra quotes around the string it returns, so that CSS
url()
references work. However this then breaks thehtml-loader
(bhovhannes/svg-url-loader#126) and "require() string from JS" use-cases, which require consumers to remember to set the loader'snoquotes
option tofalse
(eg neutrinojs/neutrino#334).However I think this is ideally something that should be fixed in
css-loader
itself, meaningsvg-url-loader
could stop wrapping everything in quotes, solving the other problems.Thoughts? :-)
For quick reference, the relevant package versions in the testcase repo's
yarn.lock
are:webpack 3.6.0, css-loader 0.28.7, raw-loader 0.5.1, html-loader 0.5.1, extract-text-webpack-plugin 3.3.0.
The text was updated successfully, but these errors were encountered: