Support relative URLs
The `new URL()` constructor currently requires at least one of its arguments to be an absolute URL. ```js new URL('./page.html', 'https://site.com/help/'); // OK new URL('./page.html', '/help/'); // Uncaught TypeError: URL constructor: /public_html/ is not a valid URL. ``` That requirement is painful because determining which absolute URL to use as a base can be difficult or impossible in many circumstances. In a regular browser context, `document.baseURI` should be used. In Web Workers, `self.location` should be used. In Deno, `window.location` should be used but only if the `--location` command line option was used. In Node, there is no absolute URL to use. Trying to write isomorphic code that satisfies this requirement is quite error prone. Additionally, in many cases it would be useful to parse and resolve relative URLs against each other without knowing an absolute base URL ahead of time. ```js // Desired output - these currently do not work new URL('/to', '/from').toString(); // '/to' new URL('/to', '//from.com/').toString(); // '//from.com/to' ``` The lack of support for use cases involving only relative URLs is causing me to remove WHATWG URL from Ky, a popular HTTP request library, in favor of our own string replacement. See: https://github.com/sindresorhus/ky/pull/271 ### Desired API and whether to update the existing `new URL()` API or create a new API? From my perspective, updating the `new URL()` constructor so it can handle a relative URL in the `base
Posted by sholladay on Jul 17, 2020, 3:35 AM
Tags
Related issues
- This is the biggest problem with contracts, there's simply no way to actually say "please always execute this check".
- I don't disagree with you on this, I worked my whole life in corporate and haven't worked as a OSS maintainer before, though I will _and ...
- the new VSCode UI, looks cute, i don't like it.
- I've been working on my own private harness for the past 8 months, and I've been collecting ideas from such repos I've stumbled upon.
- The way AI is able to interact with outside resources is pretty impressive, but the quality of code it produces to me is still questionab...
- Add PR-style review comments in Git Diff UI that feed into the active agent thread
Raise real-world problems, find people facing the same issue, and discuss solutions.3,500 issues0 comments
ux (Software)
This is the biggest problem with contracts, there's simply no way to actually say "please always execute this check".
I don't disagree with you on this, I worked my whole life in corporate and haven't worked as a OSS maintainer before, though I will _and ...
the new VSCode UI, looks cute, i don't like it.
I've been working on my own private harness for the past 8 months, and I've been collecting ideas from such repos I've stumbled upon.
The way AI is able to interact with outside resources is pretty impressive, but the quality of code it produces to me is still questionab...
Add PR-style review comments in Git Diff UI that feed into the active agent thread
Thanks for indulging me so far, by the way, I really appreciate this discussion, it's very stimulating.
Migrate GDScript to the GDExtension mechanism and overhaul the implementation
Support relative URLs
The `new URL()` constructor currently requires at least one of its arguments to be an absolute URL. ```js new URL('./page.html', 'https://site.com/help/'); // OK new URL('./page.html', '/help/'); // Uncaught TypeError: URL constructor: /public_html/ is not a valid URL. ``` That requirement is painful because determining which absolute URL to use as a base can be difficult or impossible in many circumstances. In a regular browser context, `document.baseURI` should be used. In Web Workers, `self.location` should be used. In Deno, `window.location` should be used but only if the `--location` command line option was used. In Node, there is no absolute URL to use. Trying to write isomorphic code that satisfies this requirement is quite error prone. Additionally, in many cases it would be useful to parse and resolve relative URLs against each other without knowing an absolute base URL ahead of time. ```js // Desired output - these currently do not work new URL('/to', '/from').toString(); // '/to' new URL('/to', '//from.com/').toString(); // '//from.com/to' ``` The lack of support for use cases involving only relative URLs is causing me to remove WHATWG URL from Ky, a popular HTTP request library, in favor of our own string replacement. See: https://github.com/sindresorhus/ky/pull/271 ### Desired API and whether to update the existing `new URL()` API or create a new API? From my perspective, updating the `new URL()` constructor so it can handle a relative URL in the `base
Comments (0)
No comments yet. Start the discussion.