diff --git a/lib/source-map/util.js b/lib/source-map/util.js index 3bc13640..976f6cab 100644 --- a/lib/source-map/util.js +++ b/lib/source-map/util.js @@ -192,6 +192,10 @@ define(function (require, exports, module) { * @param aPath The path or URL to be made relative to aRoot. */ function relative(aRoot, aPath) { + if (aRoot === "") { + aRoot = "."; + } + aRoot = aRoot.replace(/\/$/, ''); // XXX: It is possible to remove this block, and the tests still pass! diff --git a/test/source-map/test-util.js b/test/source-map/test-util.js index 44f7b7f6..997d1a26 100644 --- a/test/source-map/test-util.js +++ b/test/source-map/test-util.js @@ -203,6 +203,14 @@ define(function (require, exports, module) { exports['test relative()'] = function (assert, util) { assert.equal(libUtil.relative('/the/root', '/the/root/one.js'), 'one.js'); assert.equal(libUtil.relative('/the/root', '/the/rootone.js'), '/the/rootone.js'); + + assert.equal(libUtil.relative('', '/the/root/one.js'), '/the/root/one.js'); + assert.equal(libUtil.relative('.', '/the/root/one.js'), '/the/root/one.js'); + assert.equal(libUtil.relative('', 'the/root/one.js'), 'the/root/one.js'); + assert.equal(libUtil.relative('.', 'the/root/one.js'), 'the/root/one.js'); + + assert.equal(libUtil.relative('/', '/the/root/one.js'), 'the/root/one.js'); + assert.equal(libUtil.relative('/', 'the/root/one.js'), 'the/root/one.js'); }; });