Skip to content

Commit

Permalink
Fixed to handle the colon in non-protocol separation role in the firs…
Browse files Browse the repository at this point in the history
…t part.
  • Loading branch information
Tero Keski-Valkama committed Jan 11, 2018
1 parent be99b10 commit 9212db7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
8 changes: 4 additions & 4 deletions lib/url-join.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@
var resultArray = [];

// If the first part is a plain protocol, we combine it with the next part.
if (strArray[0].match(/:\/*$/) && strArray.length > 1) {
if (strArray[0].match(/^[^/:]+:\/*$/) && strArray.length > 1) {
var first = strArray.shift();
strArray[0] = first + strArray[0];
}

// There must be two or three slashes in the file protocol, two slashes in anything else.
if (strArray[0].match(/file:\/\/\//)) {
strArray[0] = strArray[0].replace(/:\/*/, ':///');
if (strArray[0].match(/^file:\/\/\//)) {
strArray[0] = strArray[0].replace(/^([^/:]+):\/*/, '$1:///');
} else {
strArray[0] = strArray[0].replace(/:\/*/, '://');
strArray[0] = strArray[0].replace(/^([^/:]+):\/*/, '$1://');
}

for (var i = 0; i < strArray.length; i++) {
Expand Down
5 changes: 5 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ describe('url join', function () {
.should.eql('/test');
});

it('should merge a path with colon properly', function(){
urljoin('/users/:userId', '/cars/:carId')
.should.eql('/users/:userId/cars/:carId');
});

it('should merge slashes in protocol correctly', function () {
urljoin('http://example.org', 'a')
.should.eql('http://example.org/a');
Expand Down

0 comments on commit 9212db7

Please sign in to comment.