Fixes #463 - relative remote @import URLs.
authorSiguršur Gušbrandsson <sigurdur@sigginet.info>
Mon, 16 Feb 2015 21:35:19 +0000 (21:35 +0000)
committerJakub Pawlowicz <contact@jakubpawlowicz.com>
Tue, 17 Feb 2015 19:49:13 +0000 (19:49 +0000)
Testcase:
cleancss -d --root http://jeffwalker.com/wp-content/themes/salient-child/ http://jeffwalker.com/wp-content/themes/salient-child/style.css?ver=4.1.1

lib/imports/inliner.js
test/protocol-imports-test.js

index e7babd7..ddb57d3 100644 (file)
@@ -264,7 +264,7 @@ function inlineRemoteResource(importedFile, mediaQuery, context) {
 
       var newContext = override(context, {
         isRemote: true,
-        relativeTo: parsedUrl.protocol + '//' + parsedUrl.host
+        relativeTo: parsedUrl.protocol + '//' + parsedUrl.host + parsedUrl.pathname
       });
 
       importFrom(importedData, newContext);
index 5d5ba76..1c20a62 100644 (file)
@@ -424,5 +424,29 @@ vows.describe('protocol imports').addBatch({
       assert.isFalse(this.reqMocks.isDone());
       nock.cleanAll();
     }
+  },
+  'of a remote file that imports relative stylesheets': {
+    topic: function() {
+      var source = '@import url(http://127.0.0.1/test/folder/remote.css);';
+      this.reqMocks = nock('http://127.0.0.1')
+        .get('/test/folder/remote.css')
+        .reply(200, '@import url(../otherfolder/remote.css);@import url(deepersubfolder/fonts.css);')
+        .get('/test/otherfolder/remote.css')
+        .reply(200, 'div{padding:0}')
+        .get('/test/folder/deepersubfolder/fonts.css')
+        .reply(200, 'a{color:red}');
+
+      new CleanCSS().minify(source, this.callback);
+    },
+    'should not raise errors': function (error, minified) {
+      assert.isEmpty(minified.errors);
+    },
+    'should process @import': function (error, minified) {
+      assert.equal(minified.styles, 'div{padding:0}a{color:red}');
+    },
+    teardown: function() {
+      assert.isTrue(this.reqMocks.isDone());
+      nock.cleanAll();
+    }
   }
 }).export(module);