Skip to content

Commit

Permalink
Fix a bug when base is set to root path
Browse files Browse the repository at this point in the history
  • Loading branch information
lifesinger committed Jan 28, 2013
1 parent dc04cc6 commit 8bbba63
Show file tree
Hide file tree
Showing 14 changed files with 38 additions and 139 deletions.
3 changes: 2 additions & 1 deletion dist/sea-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) === "/" ? "" : "/"))
}
}

Expand Down
2 changes: 1 addition & 1 deletion dist/sea.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/sea.js.map

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion src/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,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) === "/" ? "" : "/"))
}
}

Expand Down
20 changes: 0 additions & 20 deletions tests/issues/config-base-is-root/js/main.js

This file was deleted.

36 changes: 0 additions & 36 deletions tests/issues/config-base-is-root/test.html

This file was deleted.

5 changes: 0 additions & 5 deletions tests/issues/config-base/js/a.js

This file was deleted.

3 changes: 0 additions & 3 deletions tests/issues/config-base/js/biz/b.js

This file was deleted.

3 changes: 0 additions & 3 deletions tests/issues/config-base/js/biz/sub/c.js

This file was deleted.

28 changes: 0 additions & 28 deletions tests/issues/config-base/js/main.js

This file was deleted.

3 changes: 0 additions & 3 deletions tests/issues/config-base/js/xxlib/1.0.0/xxlib.js

This file was deleted.

37 changes: 0 additions & 37 deletions tests/issues/config-base/test.html

This file was deleted.

23 changes: 23 additions & 0 deletions tests/specs/config/base/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,36 @@ define(function(require) {
test.assert(a.name === 'a', a.name)


// relative
seajs.config({
base: './'
})

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()

})
Expand Down
9 changes: 9 additions & 0 deletions tests/specs/util/path.js
Original file line number Diff line number Diff line change
Expand Up @@ -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()

});
Expand Down

0 comments on commit 8bbba63

Please sign in to comment.