Skip to content

Commit

Permalink
fix(path): Join protocol independent paths
Browse files Browse the repository at this point in the history
  • Loading branch information
Diego Torres committed Mar 2, 2015
1 parent e8fd833 commit 34655ae
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ export function join(path1, path2) {
return path1;
}

urlPrefix = path1.indexOf('/') === 0 ? '/' : '';
urlPrefix = path1.indexOf('//') === 0 ? '//' :
path1.indexOf('/') === 0 ? '/' : '';

url1 = path1.split('/');
url2 = path2.split('/');
Expand Down
28 changes: 28 additions & 0 deletions test/path.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,34 @@ describe('join', () => {
expect(join(path1, path2)).toBe('http://durandal.io/two');
});

it('can combine a protocol independent path and a simple path', () => {
var path1 = '//durandal.io';
var path2 = 'two';

expect(join(path1, path2)).toBe('//durandal.io/two');
});

it('can combine a protocol independent path and a simple path with slash', () => {
var path1 = '//durandal.io';
var path2 = '/two';

expect(join(path1, path2)).toBe('//durandal.io/two');
});

it('can combine a protocol independent path and a simple path with a dot', () => {
var path1 = '//durandal.io';
var path2 = './two';

expect(join(path1, path2)).toBe('//durandal.io/two');
});

it('can combine a protocol independent path and a relative path', () => {
var path1 = '//durandal.io/somewhere';
var path2 = '../two';

expect(join(path1, path2)).toBe('//durandal.io/two');
});

it('can combine a complex path and a relative path', () => {
var path1 = 'one/three';
var path2 = '../two';
Expand Down

0 comments on commit 34655ae

Please sign in to comment.