Skip to content
This repository was archived by the owner on Oct 9, 2020. It is now read-only.

Commit 13e5821

Browse files
authored
Merge pull request #138 from papandreou/fix/rootRelativeUrls
Fix root relative urls when there's no browserRootURL setting
2 parents 5889e06 + d846e3a commit 13e5821

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

css-plugin-base-builder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ exports.bundle = function(loads, compileOpts, outputOpts) {
122122
}
123123
}), atUrl({
124124
url: function(fileName, decl, from, dirname, to, options, result) {
125-
if ((absUrl(fileName) && fileName.charAt(0) !== '/') || fileName.match(/^%23/))
125+
if ((absUrl(fileName) && (!loader.browserRootURL || fileName.charAt(0) !== '/')) || fileName.match(/^%23/))
126126
return fileName;
127127

128128
// dirname may be renormalized to cwd

test/css.builder.spec.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,41 @@ describe('CSS Builder', function() {
2525
});
2626
});
2727

28+
describe('with a browserRootURL config', function () {
29+
it('should preprend it to a relative url(...) reference', function () {
30+
var builder = new Builder();
31+
builder.config(System.getConfig());
32+
builder.config({
33+
browserRootURL: 'https://example.com/',
34+
rootURL: './test'
35+
});
36+
return builder.compile('test/data/test.css!', {minify: false}).then((results) => {
37+
return expect(results.source).to.contain("body{background-color:red;background-image:url(https://example.com/data/x.png)}");
38+
});
39+
});
40+
41+
it('should preprend it to a root-relative url(...) reference', function () {
42+
var builder = new Builder();
43+
builder.config(System.getConfig());
44+
builder.config({
45+
browserRootURL: 'https://example.com/',
46+
rootURL: './test'
47+
});
48+
return builder.compile('test/data/rootRelative.css!', {minify: false}).then((results) => {
49+
return expect(results.source).to.contain("body{background-color:red;background-image:url(https://example.com/path/to/x.png)}");
50+
});
51+
});
52+
});
53+
54+
// https://github.com/systemjs/plugin-css/pull/135#commitcomment-24415595
55+
it('should handle a root-relative url when no rootURL and no browserRootURL are configured', function () {
56+
var builder = new Builder();
57+
builder.config(System.getConfig());
58+
return builder.compile('test/data/rootRelative.css!', {minify: false}).then((results) => {
59+
return expect(results.source).to.contain("body{background-color:red;background-image:url(/path/to/x.png)}");
60+
});
61+
});
62+
2863
it('Should support buildCSS: false', function() {
2964
var builder = new Builder();
3065
builder.config(System.getConfig());

test/data/rootRelative.css

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
@import "./dep.css";
2+
3+
body {
4+
background-color: red;
5+
background-image: url(/path/to/x.png);
6+
}

0 commit comments

Comments
 (0)