Closed
Description
- Version:
Node 12.10.0
- Platform:
macOS 64bit
- Subsystem:
When using new URL
in Nodejs the result of passing an invalid URL to the constructor is inconsistent with the result returned by the same call inside the browser. For example(where url == https://<script></script>
:
try {
let websiteURL = new URL(url);
} catch (error) {
console.error(err);
}
running the above in browser devtools return the following expected result:
TypeError: https://<script></script> is not a valid URL.
Running the same in Nodejs, returns the following:
URL {
href: 'https://<script></script%3E',
origin: 'https://<script><',
protocol: 'https:',
username: '',
password: '',
host: '<script><',
hostname: '<script><',
port: '',
pathname: '/script%3E',
search: '',
searchParams: URLSearchParams {},
hash: ''
}