Skip to content

Commit 8b16ba3

Browse files
mscdexsilverwind
authored andcommitted
url: fix off-by-one error with parse()
Fixes: #5393 PR-URL: #5394 Reviewed-By: Myles Borins <myles.borins@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Rod Vagg <rod@vagg.org> Reviewed-By: Evan Lucas <evanlucas@me.com>
1 parent 3a331b6 commit 8b16ba3

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/url.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ function validateHostname(self, rest, hostname) {
413413
}
414414
// Invalid host character
415415
self.hostname = hostname.slice(0, i);
416-
if (i < hostname.length - 1)
416+
if (i < hostname.length)
417417
return '/' + hostname.slice(i) + rest;
418418
break;
419419
}

test/parallel/test-url.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -851,6 +851,21 @@ var parseTests = {
851851
pathname: '/:npm/npm',
852852
path: '/:npm/npm',
853853
href: 'git+ssh://git@github.com/:npm/npm'
854+
},
855+
856+
'https://*': {
857+
protocol: 'https:',
858+
slashes: true,
859+
auth: null,
860+
host: '',
861+
port: null,
862+
hostname: '',
863+
hash: null,
864+
search: null,
865+
query: null,
866+
pathname: '/*',
867+
path: '/*',
868+
href: 'https:///*'
854869
}
855870

856871
};

0 commit comments

Comments
 (0)