From dfe45f13e7fd9d509aaec0db37d46ec46dd1e498 Mon Sep 17 00:00:00 2001 From: Brian White Date: Tue, 23 Feb 2016 14:38:23 -0500 Subject: [PATCH] url: fix off-by-one error with parse() Fixes: https://github.com/nodejs/node/issues/5393 PR-URL: https://github.com/nodejs/node/pull/5394 Reviewed-By: Myles Borins Reviewed-By: Roman Reiss Reviewed-By: Rod Vagg Reviewed-By: Evan Lucas --- lib/url.js | 2 +- test/parallel/test-url.js | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/url.js b/lib/url.js index 76fbf62f6d78d1..67633a612c159f 100644 --- a/lib/url.js +++ b/lib/url.js @@ -413,7 +413,7 @@ function validateHostname(self, rest, hostname) { } // Invalid host character self.hostname = hostname.slice(0, i); - if (i < hostname.length - 1) + if (i < hostname.length) return '/' + hostname.slice(i) + rest; break; } diff --git a/test/parallel/test-url.js b/test/parallel/test-url.js index 9aa2682cbcb523..760303e98bb6bb 100644 --- a/test/parallel/test-url.js +++ b/test/parallel/test-url.js @@ -851,6 +851,21 @@ var parseTests = { pathname: '/:npm/npm', path: '/:npm/npm', href: 'git+ssh://git@github.com/:npm/npm' + }, + + 'https://*': { + protocol: 'https:', + slashes: true, + auth: null, + host: '', + port: null, + hostname: '', + hash: null, + search: null, + query: null, + pathname: '/*', + path: '/*', + href: 'https:///*' } };