Skip to content

Commit

Permalink
fix(module-types): ignore undefined when checking for quotes in css u…
Browse files Browse the repository at this point in the history
…rl strings (#2467)
  • Loading branch information
jackw committed Aug 16, 2023
1 parent 541edff commit 61bc72f
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/extras/module-types.js
Expand Up @@ -40,7 +40,7 @@ import { resolveUrl } from '../common.js';
return res.text()
.then(function (source) {
source = source.replace(/url\(\s*(?:(["'])((?:\\.|[^\n\\"'])+)\1|((?:\\.|[^\s,"'()\\])+))\s*\)/g, function (match, quotes, relUrl1, relUrl2) {
return 'url(' + quotes + resolveUrl(relUrl1 || relUrl2, url) + quotes + ')';
return ['url(', quotes, resolveUrl(relUrl1 || relUrl2, url), quotes, ')'].join('');
});
return new Response(new Blob([
'System.register([],function(e){return{execute:function(){var s=new CSSStyleSheet();s.replaceSync(' + JSON.stringify(source) + ');e("default",s)}}})'
Expand Down
11 changes: 11 additions & 0 deletions test/browser/core.js
Expand Up @@ -227,6 +227,17 @@ suite('SystemJS Standard Tests', function() {
});
});

test('should handle css modules with urls without quotes', function () {
return System.import('fixturesbase/css-modules/url-without-quotes.css').then(function (m) {
assert.ok(m);
assert.ok(isCSSStyleSheet(m.default));
assert.equal(m.default.cssRules[0].cssText,'.hello { background-image: url("http://localhost:8080/test/fixtures/css-modules/path/to/image.png"); }')
assert.equal(m.default.cssRules[1].cssText,'.world { background-image: url("http://localhost:8080/test/fixtures/css-modules/path/to/image.png"); }')
assert.equal(m.default.cssRules[2].cssText,'body { background-image: url("http://localhost:8080/test/fixtures/css-modules/path/to/image.png"); }')
document.adoptedStyleSheets = document.adoptedStyleSheets.concat(m.default);
});
});

test('should support application/javascript css module override', function () {
return System.import('fixturesbase/css-modules/javascript.css').then(function (m) {
assert.ok(m);
Expand Down
9 changes: 9 additions & 0 deletions test/fixtures/css-modules/url-without-quotes.css
@@ -0,0 +1,9 @@
.hello {
background-image: url(./path/to/image.png);
}
.world {
background-image: url('./path/to/image.png');
}
body {
background-image: url("./path/to/image.png");
}

0 comments on commit 61bc72f

Please sign in to comment.