Skip to content

Commit

Permalink
fix: url parser should throw error on invalid ipv4
Browse files Browse the repository at this point in the history
  • Loading branch information
anonrig committed Apr 29, 2022
1 parent 27ecf1d commit 0af57b1
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/node_url.cc
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,7 @@ void URLHost::ParseIPv4Host(const char* input, size_t length, bool* is_ipv4) {
pointer++;
}
CHECK_GT(parts, 0);
CHECK_LE(parts, 4);
*is_ipv4 = true;

// If any but the last item in numbers is greater than 255, return failure.
Expand Down
8 changes: 8 additions & 0 deletions test/parallel/test-whatwg-url-constructor.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,3 +142,11 @@ function runURLSearchParamTests() {
runURLSearchParamTests()
runURLConstructorTests()
/* eslint-enable */

const message = {
code: 'ERR_INVALID_URL',
name: 'TypeError',
message: 'Invalid URL',
};

assert_throws(() => new URL('https://256.256.256.256.256'), message);

0 comments on commit 0af57b1

Please sign in to comment.