Skip to content

Commit

Permalink
[fix] Fixes relative path resolving #199 #200
Browse files Browse the repository at this point in the history
  • Loading branch information
3rd-Eden committed Feb 18, 2021
1 parent 3ac7774 commit 9819b59
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
5 changes: 3 additions & 2 deletions index.js
Expand Up @@ -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
};
}

Expand Down
14 changes: 14 additions & 0 deletions test/test.js
Expand Up @@ -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);
Expand Down

0 comments on commit 9819b59

Please sign in to comment.