Skip to content

Node crashes on new URL #48254

@jetibest

Description

@jetibest

Version

v19.8.1

Platform

Linux pc 6.2.7-arch1-1 #1 SMP PREEMPT_DYNAMIC Sat, 18 Mar 2023 01:06:36 +0000 x86_64 GNU/Linux

Subsystem

url

What steps will reproduce the bug?

Running in Node:

Welcome to Node.js v19.8.1.
Type ".help" for more information.
> new URL('', 'localhost:80')
/usr/include/c++/12.2.1/string_view:239: constexpr const std::basic_string_view<_CharT, _Traits>::value_type& std::basic_string_view<_CharT, _Traits>::operator[](size_type) const [with _CharT = char; _Traits = std::char_traits<char>; const_reference = const char&; size_type = long unsigned int]: Assertion '__pos < this->_M_len' failed.
Aborted (core dumped)

How often does it reproduce? Is there a required condition?

There's no issue when the second argument is only a hostname, or a port. It only appears to lead to an issue when both the hostname and port is given in the second argument.

What is the expected behavior? Why is that the expected behavior?

An Error should be thrown with code ERR_INVALID_URL:

Uncaught TypeError [ERR_INVALID_URL]: Invalid URL
    at __node_internal_captureLargerStackTrace (node:internal/errors:490:5)
    at new NodeError (node:internal/errors:399:5)
    at new URL (node:internal/url:556:13) {
  input: '',
  code: 'ERR_INVALID_URL'
}

What do you see instead?

The error given in the steps to reproduce shows up, and Node crashes.

Additional information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    whatwg-urlIssues and PRs related to the WHATWG URL implementation.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions