Skip to content

Commit

Permalink
fix(join): keep trailing slash
Browse files Browse the repository at this point in the history
  • Loading branch information
escaped committed Apr 30, 2015
1 parent 5a0adbb commit 3e7ed20
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export function join(path1, path2) {

urlPrefix = path1.indexOf('//') === 0 ? '//' :
path1.indexOf('/') === 0 ? '/' : '';
trailingSlash = path2.slice(-1) == '/' ? '/' : '';

url1 = path1.split('/');
url2 = path2.split('/');
Expand All @@ -82,7 +83,7 @@ export function join(path1, path2) {
}
}

return urlPrefix + url3.join('/').replace(/\:\//g, '://');;
return urlPrefix + url3.join('/').replace(/\:\//g, '://') + trailingSlash;
}

var r20 = /%20/g,
Expand Down
9 changes: 8 additions & 1 deletion test/path.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,4 +170,11 @@ describe('join', () => {

expect(join(path1, path2)).toBe('one');
});
});
it('should respect a trailing slash', () => {
var path1 = 'one/';
var path2 = 'two/';

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

0 comments on commit 3e7ed20

Please sign in to comment.