diff --git a/src/node_url.cc b/src/node_url.cc index b13c94f030fa59..1faaf5d957844c 100644 --- a/src/node_url.cc +++ b/src/node_url.cc @@ -430,7 +430,6 @@ void URLHost::ParseIPv4Host(const char* input, size_t length, bool* is_ipv4) { pointer++; } CHECK_GT(parts, 0); - *is_ipv4 = true; // If any but the last item in numbers is greater than 255, return failure. // If the last item in numbers is greater than or equal to @@ -441,6 +440,8 @@ void URLHost::ParseIPv4Host(const char* input, size_t length, bool* is_ipv4) { return; } + *is_ipv4 = true; + type_ = HostType::H_IPV4; val = static_cast(numbers[parts - 1]); for (int n = 0; n < parts - 1; n++) { diff --git a/test/parallel/test-whatwg-url-constructor.js b/test/parallel/test-whatwg-url-constructor.js index 3dc1c5986027e7..82972eddb5f8da 100644 --- a/test/parallel/test-whatwg-url-constructor.js +++ b/test/parallel/test-whatwg-url-constructor.js @@ -5,6 +5,7 @@ if (!common.hasIntl) { common.skip('missing Intl'); } +const assert = require('assert'); const fixtures = require('../common/fixtures'); const { test, assert_equals, assert_true, assert_throws } = require('../common/wpt').harness; @@ -142,3 +143,5 @@ function runURLSearchParamTests() { runURLSearchParamTests() runURLConstructorTests() /* eslint-enable */ + +assert.throws(() => new URL('https://256.256.256.256.256'), { code: 'ERR_INVALID_URL' });