Fixes #144 - skip URLs rebasing by default.
authorGoalSmashers <jakub@goalsmashers.com>
Fri, 6 Sep 2013 22:09:19 +0000 (00:09 +0200)
committerGoalSmashers <jakub@goalsmashers.com>
Fri, 6 Sep 2013 22:09:19 +0000 (00:09 +0200)
History.md
lib/images/url-rebase.js
lib/images/url-rewriter.js
test/binary-test.js
test/unit-test.js

index 342a58f..5e3d857 100644 (file)
@@ -1,3 +1,8 @@
+1.1.1 / 2013-xx-xx
+==================
+
+* Fixed issue [#144](https://github.com/GoalSmashers/clean-css/issues/144) - skip URLs rebasing by default.
+
 1.1.0 / 2013-09-06
 ==================
 
index c5a00e2..78792dc 100644 (file)
@@ -10,12 +10,18 @@ module.exports = {
       fromBase: options.relativeTo
     };
 
+    if (!rebaseOpts.absolute && !rebaseOpts.relative)
+      return data;
+
     if (rebaseOpts.absolute)
       rebaseOpts.toBase = path.resolve(options.root);
 
     if (rebaseOpts.relative)
       rebaseOpts.toBase = path.resolve(path.dirname(options.target));
 
+    if (!rebaseOpts.fromBase || !rebaseOpts.toBase)
+      return data;
+
     return UrlRewriter.process(data, rebaseOpts);
   }
 };
index 6903edc..b41056f 100644 (file)
@@ -38,12 +38,6 @@ module.exports = {
     if (specialUrl)
       return url;
 
-    if (!options.absolute && !options.relative)
-      throw new Error('Relative url found: \'' + url + '\' but there is no way to resolve it (hint: use `root` or `output` options)');
-
-    if (!options.fromBase || !options.toBase)
-      return url;
-
     if (options.absolute) {
       rebased = path
         .resolve(path.join(options.fromBase, url))
index fde7e9d..2d132cf 100644 (file)
@@ -150,9 +150,8 @@ exports.commandsSuite = vows.describe('binary commands').addBatch({
   }),
   'relative image paths': {
     'no root & output': binaryContext('./test/data/partials-relative/base.css', {
-      'should raise error': function(error, stdout) {
-        assert.equal(stdout, '');
-        assert.notEqual(error, null);
+      'should leave paths': function(error, stdout) {
+        assert.equal(stdout, 'a{background:url(../partials/extra/down.gif) 0 0 no-repeat}');
       }
     }),
     'root but no output': binaryContext('-r ./test ./test/data/partials-relative/base.css', {
index 49e1776..096aac9 100644 (file)
@@ -641,17 +641,14 @@ path")}',
     ]
   }),
   'urls rewriting - no root or target': cssContext({
-    'no @import': [
-      'a{background:url(test/data/partials/extra/down.gif) 0 0 no-repeat}',
-      null
-    ],
+    'no @import': 'a{background:url(test/data/partials/extra/down.gif) 0 0 no-repeat}',
     'relative @import': [
       '@import url(test/data/partials-relative/base.css);',
-      null
+      'a{background:url(test/data/partials/extra/down.gif) 0 0 no-repeat}'
     ],
     'absolute @import': [
       '@import url(/test/data/partials-relative/base.css);',
-      null
+      'a{background:url(test/data/partials/extra/down.gif) 0 0 no-repeat}'
     ]
   }),
   'urls rewriting - root but no target': cssContext({