Skip to content

Commit fed6d9e

Browse files
committed
[fix] Add a leading slash only if the URL is special
If the value of the `pathname` property does not start with a `/`, add it only if the URL is special.
1 parent 94872e7 commit fed6d9e

File tree

2 files changed

+3
-6
lines changed

2 files changed

+3
-6
lines changed

index.js

+1-4
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,7 @@ function Url(address, location, parser) {
347347
// Default to a / for pathname if none exists. This normalizes the URL
348348
// to always have a /
349349
//
350-
if (
351-
url.pathname.charAt(0) !== '/'
352-
&& (url.hostname || url.protocol === 'file:')
353-
) {
350+
if (url.pathname.charAt(0) !== '/' && isSpecial(url.protocol)) {
354351
url.pathname = '/' + url.pathname;
355352
}
356353

test/test.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -361,8 +361,8 @@ describe('url-parse', function () {
361361
url = 'foo://example.com';
362362
parsed = parse(url);
363363
assume(parsed.hostname).equals('example.com');
364-
assume(parsed.pathname).equals('/');
365-
assume(parsed.href).equals('foo://example.com/');
364+
assume(parsed.pathname).equals('');
365+
assume(parsed.href).equals('foo://example.com');
366366
assume(parsed.slashes).is.true();
367367

368368
url = 'foo:///example.com';

0 commit comments

Comments
 (0)