From 8bbba63e5e3faeb5d1540b7efb3632077bc31ba3 Mon Sep 17 00:00:00 2001 From: lifesinger Date: Mon, 28 Jan 2013 11:44:47 +0800 Subject: [PATCH] Fix a bug when base is set to root path --- dist/sea-debug.js | 3 +- dist/sea.js | 2 +- dist/sea.js.map | 2 +- src/config.js | 3 +- tests/issues/config-base-is-root/js/main.js | 20 ---------- tests/issues/config-base-is-root/test.html | 36 ------------------ tests/issues/config-base/js/a.js | 5 --- tests/issues/config-base/js/biz/b.js | 3 -- tests/issues/config-base/js/biz/sub/c.js | 3 -- tests/issues/config-base/js/main.js | 28 -------------- .../config-base/js/xxlib/1.0.0/xxlib.js | 3 -- tests/issues/config-base/test.html | 37 ------------------- tests/specs/config/base/main.js | 23 ++++++++++++ tests/specs/util/path.js | 9 +++++ 14 files changed, 38 insertions(+), 139 deletions(-) delete mode 100644 tests/issues/config-base-is-root/js/main.js delete mode 100644 tests/issues/config-base-is-root/test.html delete mode 100644 tests/issues/config-base/js/a.js delete mode 100644 tests/issues/config-base/js/biz/b.js delete mode 100644 tests/issues/config-base/js/biz/sub/c.js delete mode 100644 tests/issues/config-base/js/main.js delete mode 100644 tests/issues/config-base/js/xxlib/1.0.0/xxlib.js delete mode 100644 tests/issues/config-base/test.html diff --git a/dist/sea-debug.js b/dist/sea-debug.js index cec84c89..a6fe24f0 100644 --- a/dist/sea-debug.js +++ b/dist/sea-debug.js @@ -1057,7 +1057,8 @@ function checkConfigConflict(prev, curr, k, key) { function makeBaseAbsolute() { var base = configData.base if (!isAbsolute(base)) { - configData.base = id2Uri((isRoot(base) ? "" : "./") + base + "/") + configData.base = id2Uri((isRoot(base) ? "" : "./") + base + + (base.charAt(base.length - 1) === "/" ? "" : "/")) } } diff --git a/dist/sea.js b/dist/sea.js index 1193ae05..66274073 100644 --- a/dist/sea.js +++ b/dist/sea.js @@ -16,5 +16,5 @@ c){if(!c)return h;(u[a]||(u[a]=[])).push(c);return h};h.off=function(a,c){if(!a& "/"!==m.charAt(0)&&(m="/"+m);f=f.protocol+"//"+f.host+m;-1Number(v.replace(/.*AppleWebKit\/(\d+)\..*/, "$1")),ma=0 - - - -Issue Test - - - - - -

- -

- -
- - - - \ No newline at end of file diff --git a/tests/issues/config-base/js/a.js b/tests/issues/config-base/js/a.js deleted file mode 100644 index 32a09992..00000000 --- a/tests/issues/config-base/js/a.js +++ /dev/null @@ -1,5 +0,0 @@ -define(function(require, exports) { - - exports.a = 'a'; - -}); diff --git a/tests/issues/config-base/js/biz/b.js b/tests/issues/config-base/js/biz/b.js deleted file mode 100644 index fe7975fb..00000000 --- a/tests/issues/config-base/js/biz/b.js +++ /dev/null @@ -1,3 +0,0 @@ -define(function(require, exports) { - exports.name = 'b' -}); diff --git a/tests/issues/config-base/js/biz/sub/c.js b/tests/issues/config-base/js/biz/sub/c.js deleted file mode 100644 index 842b0d6f..00000000 --- a/tests/issues/config-base/js/biz/sub/c.js +++ /dev/null @@ -1,3 +0,0 @@ -define(function(require, exports) { - exports.name = 'c' -}); diff --git a/tests/issues/config-base/js/main.js b/tests/issues/config-base/js/main.js deleted file mode 100644 index 9e80f989..00000000 --- a/tests/issues/config-base/js/main.js +++ /dev/null @@ -1,28 +0,0 @@ -define(function(require) { - - var test = require('../../../test'); - - var a = require('a'); - var b = require('biz/b'); - var c = require('biz/sub/c'); - var xxlib = require('xxlib'); - - test.assert(a.a === 'a', 'a is ok'); - test.assert(b.b === 'b', 'b is ok'); - test.assert(c.c === 'c', 'c is ok'); - test.assert(xxlib.name === 'xxlib', 'xxlib is ok'); - - - seajs.config({ - base: 'xx' - }); - - test.assert( - require.resolve('z').indexOf('/config-base/xx/z.js') > 0, - require.resolve('z') - ); - - - test.done(); - -}); diff --git a/tests/issues/config-base/js/xxlib/1.0.0/xxlib.js b/tests/issues/config-base/js/xxlib/1.0.0/xxlib.js deleted file mode 100644 index 7a3e6fbe..00000000 --- a/tests/issues/config-base/js/xxlib/1.0.0/xxlib.js +++ /dev/null @@ -1,3 +0,0 @@ -define('xxlib', function(require, exports) { - exports.name = 'xxlib' -}); diff --git a/tests/issues/config-base/test.html b/tests/issues/config-base/test.html deleted file mode 100644 index 698053d0..00000000 --- a/tests/issues/config-base/test.html +++ /dev/null @@ -1,37 +0,0 @@ - - - - -Issue Test - - - - - -

- https://groups.google.com/forum/#!topic/seajs/SPJosS0Fl80 -

- -
- - - - \ No newline at end of file diff --git a/tests/specs/config/base/main.js b/tests/specs/config/base/main.js index b31e4732..4fd5a2e8 100644 --- a/tests/specs/config/base/main.js +++ b/tests/specs/config/base/main.js @@ -12,6 +12,7 @@ define(function(require) { test.assert(a.name === 'a', a.name) + // relative seajs.config({ base: './' }) @@ -19,6 +20,28 @@ define(function(require) { var base = seajs.config.data.base test.assert(/tests\/specs\/config\/$/.test(base), base) + + // root + seajs.config({ + base: '/root-path/' + }) + + function expectedPath(str) { + return location.protocol + '//' + location.host + '/root-path/' + str + '.js' + } + + test.assert(require.resolve('z') === expectedPath('z'), require.resolve('z')) + + + // rare but allowed case + seajs.config({ + base: '/' + }) + + base = seajs.config.data.base + test.assert(location.href.indexOf(base) === 0, base) + + test.next() }) diff --git a/tests/specs/util/path.js b/tests/specs/util/path.js index 2e3be709..8f8bba68 100644 --- a/tests/specs/util/path.js +++ b/tests/specs/util/path.js @@ -120,6 +120,15 @@ define(function(require) { assert(id2Uri('./front/jquery.x.queue.js#') === pageDir + 'front/jquery.x.queue.js', 'id2Uri') + assert(isAbsolute('http://test.com/') === true, 'isAbsolute') + assert(isAbsolute('//test.com/') === true, 'isAbsolute') + assert(isAbsolute('file:///c/') === true, 'isAbsolute') + assert(isRelative('./') === true, 'isRelative') + assert(isRelative('../') === true, 'isRelative') + assert(isRoot('/') === true, 'isRoot') + assert(isTopLevel('xxx') === true, 'isTopLevel') + + test.next() });