diff --git a/index.js b/index.js index e54575a..72b27c0 100644 --- a/index.js +++ b/index.js @@ -118,12 +118,13 @@ function extractProtocol(address) { var match = protocolre.exec(address) , protocol = match[1] ? match[1].toLowerCase() : '' - , slashes = !!(match[2] && match[2].length >= 2); + , slashes = !!(match[2] && match[2].length >= 2) + , rest = match[2] && match[2].length === 1 ? '/' + match[3] : match[3]; return { protocol: protocol, slashes: slashes, - rest: match[3] + rest: rest }; } diff --git a/test/test.js b/test/test.js index 3020236..943c2df 100644 --- a/test/test.js +++ b/test/test.js @@ -209,6 +209,20 @@ describe('url-parse', function () { assume(parsed.href).equals('http://example.com/'); }); + it('correctly parses pathnames for relative paths', function () { + var url = '/dataApi/PROD/ws' + , parsed = parse(url, 'http://localhost:3000/PROD/trends'); + + assume(parsed.pathname).equals('/dataApi/PROD/ws'); + + url = '/sections/?project=default' + parsed = parse(url, 'http://example.com/foo/bar'); + + assume(parsed.pathname).equals('/sections/'); + assume(parsed.hostname).equals('example.com'); + assume(parsed.href).equals('http://example.com/sections/?project=default'); + }); + it('does not care about spaces', function () { var url = 'http://x.com/path?that\'s#all, folks' , parsed = parse(url);