Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/url-join.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ function normalize (strArray) {
throw new TypeError('Url must be a string. Received ' + component);
}

// Remove periods from the beginning of the string (eg: './foo' -> '/foo').
component = component.replace(/^[.]\//, '/');

if (i > 0) {
// Removing the starting slashes for each component but the first.
component = component.replace(/^[\/]+/, '');
Expand Down
7 changes: 7 additions & 0 deletions test/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,13 @@ test('joins a protocol with slashes', () => {
);
});

test('Remove periods from paths', () => {
assert.equal(
urlJoin('http:', 'www.google.com/', 'foo/bar','./deee', '?test=123'),
'http://www.google.com/foo/bar/deee?test=123'
);
});

test('removes extra slashes', () => {
assert.equal(
urlJoin('http:', 'www.google.com///', 'foo/bar', '?test=123'),
Expand Down