From: GoalSmashers Date: Fri, 6 Sep 2013 22:09:19 +0000 (+0200) Subject: Fixes #144 - skip URLs rebasing by default. X-Git-Url: https://git.ndcode.org/public/gitweb.cgi?a=commitdiff_plain;h=309eb014ada991bb9b4d64b0543702c4913c8787;p=clean-css.git Fixes #144 - skip URLs rebasing by default. --- diff --git a/History.md b/History.md index 342a58f3..5e3d8579 100644 --- a/History.md +++ b/History.md @@ -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 ================== diff --git a/lib/images/url-rebase.js b/lib/images/url-rebase.js index c5a00e21..78792dc6 100644 --- a/lib/images/url-rebase.js +++ b/lib/images/url-rebase.js @@ -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); } }; diff --git a/lib/images/url-rewriter.js b/lib/images/url-rewriter.js index 6903edc7..b41056fd 100644 --- a/lib/images/url-rewriter.js +++ b/lib/images/url-rewriter.js @@ -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)) diff --git a/test/binary-test.js b/test/binary-test.js index fde7e9d7..2d132cfa 100644 --- a/test/binary-test.js +++ b/test/binary-test.js @@ -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', { diff --git a/test/unit-test.js b/test/unit-test.js index 49e1776f..096aac97 100644 --- a/test/unit-test.js +++ b/test/unit-test.js @@ -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({