diff --git a/lib/url-join.js b/lib/url-join.js index 83b1a26..4d49b74 100644 --- a/lib/url-join.js +++ b/lib/url-join.js @@ -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(/^[\/]+/, ''); diff --git a/test/tests.js b/test/tests.js index 8f91011..b35cf41 100644 --- a/test/tests.js +++ b/test/tests.js @@ -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'),