diff --git a/lib/internal/url.js b/lib/internal/url.js index 25cf8a79e7617b..23340a3e5c1a01 100644 --- a/lib/internal/url.js +++ b/lib/internal/url.js @@ -143,7 +143,6 @@ class URLContext { href = ''; origin = ''; protocol = ''; - host = ''; hostname = ''; pathname = ''; search = ''; @@ -626,14 +625,13 @@ class URL { return constructHref(this[context], options); } - #onParseComplete = (href, origin, protocol, host, hostname, pathname, + #onParseComplete = (href, origin, protocol, hostname, pathname, search, username, password, port, hash, hasHost, hasOpaquePath) => { const ctx = this[context]; ctx.href = href; ctx.origin = origin; ctx.protocol = protocol; - ctx.host = host; ctx.hostname = hostname; ctx.pathname = pathname; ctx.search = search; @@ -716,7 +714,9 @@ class URL { get host() { if (!isURLThis(this)) throw new ERR_INVALID_THIS('URL'); - return this[context].host; + const port = this[context].port; + const suffix = port.length > 0 ? `:${port}` : ''; + return this[context].hostname + suffix; } set host(value) { diff --git a/src/node_url.cc b/src/node_url.cc index d41a956b1203e8..39905874bf38e1 100644 --- a/src/node_url.cc +++ b/src/node_url.cc @@ -52,16 +52,15 @@ void SetArgs(Environment* env, Local argv[12], const ada::result& url) { argv[0] = Utf8String(isolate, url->get_href()); argv[1] = Utf8String(isolate, url->get_origin()); argv[2] = Utf8String(isolate, url->get_protocol()); - argv[3] = Utf8String(isolate, url->get_host()); - argv[4] = Utf8String(isolate, url->get_hostname()); - argv[5] = Utf8String(isolate, url->get_pathname()); - argv[6] = Utf8String(isolate, url->get_search()); - argv[7] = Utf8String(isolate, url->get_username()); - argv[8] = Utf8String(isolate, url->get_password()); - argv[9] = Utf8String(isolate, url->get_port()); - argv[10] = Utf8String(isolate, url->get_hash()); - argv[11] = Boolean::New(isolate, url->host.has_value()); - argv[12] = Boolean::New(isolate, url->has_opaque_path); + argv[3] = Utf8String(isolate, url->get_hostname()); + argv[4] = Utf8String(isolate, url->get_pathname()); + argv[5] = Utf8String(isolate, url->get_search()); + argv[6] = Utf8String(isolate, url->get_username()); + argv[7] = Utf8String(isolate, url->get_password()); + argv[8] = Utf8String(isolate, url->get_port()); + argv[9] = Utf8String(isolate, url->get_hash()); + argv[10] = Boolean::New(isolate, url->host.has_value()); + argv[11] = Boolean::New(isolate, url->has_opaque_path); } void Parse(const FunctionCallbackInfo& args) { @@ -108,7 +107,6 @@ void Parse(const FunctionCallbackInfo& args) { undef, undef, undef, - undef, }; SetArgs(env, argv, out); USE(success_callback_->Call( @@ -259,7 +257,6 @@ void UpdateUrl(const FunctionCallbackInfo& args) { undef, undef, undef, - undef, }; SetArgs(env, argv, out); USE(success_callback_->Call( diff --git a/test/parallel/test-whatwg-url-custom-inspect.js b/test/parallel/test-whatwg-url-custom-inspect.js index e64f9991f5f0d9..ad7a48f72d5958 100644 --- a/test/parallel/test-whatwg-url-custom-inspect.js +++ b/test/parallel/test-whatwg-url-custom-inspect.js @@ -49,7 +49,6 @@ assert.strictEqual( href: 'https://username:password@host.name:8080/path/name/?que=ry#hash', origin: 'https://host.name:8080', protocol: 'https:', - host: 'host.name:8080', hostname: 'host.name', pathname: '/path/name/', search: '?que=ry',