Skip to content

Commit

Permalink
[fix] Add a leading slash only if the URL is special
Browse files Browse the repository at this point in the history
If the value of the `pathname` property does not start with a `/`, add
it only if the URL is special.
  • Loading branch information
lpinca committed Jul 24, 2021
1 parent 94872e7 commit fed6d9e
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 6 deletions.
5 changes: 1 addition & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -347,10 +347,7 @@ function Url(address, location, parser) {
// Default to a / for pathname if none exists. This normalizes the URL
// to always have a /
//
if (
url.pathname.charAt(0) !== '/'
&& (url.hostname || url.protocol === 'file:')
) {
if (url.pathname.charAt(0) !== '/' && isSpecial(url.protocol)) {
url.pathname = '/' + url.pathname;
}

Expand Down
4 changes: 2 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -361,8 +361,8 @@ describe('url-parse', function () {
url = 'foo://example.com';
parsed = parse(url);
assume(parsed.hostname).equals('example.com');
assume(parsed.pathname).equals('/');
assume(parsed.href).equals('foo://example.com/');
assume(parsed.pathname).equals('');
assume(parsed.href).equals('foo://example.com');
assume(parsed.slashes).is.true();

url = 'foo:///example.com';
Expand Down

0 comments on commit fed6d9e

Please sign in to comment.