Re: [whatwg/url] Consider adding a constructor to make a URL from parts (#354)

mohd-akram left a comment (whatwg/url#354)

> The problem is you can't build a URL step-by-step. Each part affects the whole. It's not really a sensible operation in the URL data model.
> 
> I suggest people just use the following:
> 
> Object.assign(new URL("https://example.com/"), { ... pieces go here ... });

This does not validate the port:

```javascript
Object.assign(new URL("https://example.com/"), { port: 'bad' });
/*
URL {
  href: 'https://example.com/',
  origin: 'https://example.com',
  protocol: 'https:',
  username: '',
  password: '',
  host: 'example.com',
  hostname: 'example.com',
  port: '',
  pathname: '/',
  search: '',
  searchParams: URLSearchParams {},
  hash: ''
}
*/
```

The port is silently ignored.

-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/url/issues/354#issuecomment-2700325738
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/url/issues/354/2700325738@github.com>

Received on Wednesday, 5 March 2025 09:19:28 UTC