Re: [whatwg/url] Support relative URLs (#531)

To try and clarify this issue: it seems that you're not asking for a definitional change but an actual behavioural change to the Web-facing `URL` API.

Specifically, the changes you seem to be asking for are:
1. If the `base` argument is not supplied, it defaults to `document.location` (the current page's URL), rather than the current behaviour which requires the `url` argument to be absolute if `base` is omitted.
2. If the `base` argument is not absolute, it is first resolved against `document.location` (the current page's URL), rather than the current behaviour which unconditionally requires the `base` argument to be absolute.

So for example, if you executed these on `https://github.com/whatwg/url/issues/531`, all of the following are currently errors, and they would change to work as follows:

```js
// Proposed API.
> new URL('to');
"https://github.com/whatwg/url/issues/to"

> new URL('to', '/from/');
"https://github.com/from/to"

> new URL('to', '//from.com/');
"https://from.com/to"
```

Technically, this is all feasible, but I don't think it's necessary or desirable. It's rather trivial to write code using the current API that  behaves like this if you want it to:

```js
// Current API.
> new URL('to', document.location);
"https://github.com/whatwg/url/issues/to"

> new URL('to', new URL('/from/', document.location));
"https://github.com/from/to"

> new URL('to', new URL('//from.com/', document.location));
"https://from.com/to"
```

I personally prefer not to change this. The current API forces you to be explicit about incorporating the current document's location, so it's clear to anyone reading the code that the current page's URL might leak into the result. When you don't use `document.location` as a base, it's a pure mathematical function of the inputs, and will produce the same output on any web page. That's a good property which I don't think we should break.

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

Received on Monday, 20 July 2020 01:06:51 UTC