-
-
Notifications
You must be signed in to change notification settings - Fork 2k
fix: allow calling fetch
for any scheme
#10699
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: 5cba1a2 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Continuation of #10656
Originally posted by @benmccann in #10656 (comment) The "+" is in there, hidden in plain sight. The uppercase letters are also matched due to insensitive flag. |
fetch
for any scheme
Thanks. This looks good to me, but could we refactor this shared logic into a util method like |
@benmccann, I have put some thought into your suggestion and I think it would be better to not have a function and accept that this regex will be used at two places. The test answers the questions "Is this a relative URL?" with an approximation that is just good enough for the specific case. For example, it will tell you that "mailto:[email protected]" is an absolute URL. But it's a URI and neither absolute nor relative. (Which we can ignore because a developer wouldn't do this.) Putting this into a function may encourage devs to use it elsewhere, which could cause unintentional side effects. Of course, we could do proper validation and cover all the edge cases as well, but that would introduce unnecessary complexity. I do not have an alternative suggestion. I added some comments to the two lines to clarify what is tested and why. Let me know your thoughts. If you think the concerns are negligible, I will refactor. |
That's a fair point. How about extracting the regex out into a constant like |
@benmccann I like that. There's already a import { BROWSER } from 'esm-env';
// <<<<<<<<<<<<<<<
/** @constant - Matches a URI scheme (https://www.rfc-editor.org/rfc/rfc3986#section-3.1)
@type {RegExp}
@default
*/
export const SCHEME = /^[a-z][a-z\d+\-.]+:/i;
// >>>>>>>>>>>>>>>
const absolute = /^([a-z]+:)?\/?\//;
const scheme = /^[a-z]+:/;
/**
* @param {string} base
* @param {string} path
*/
export function resolve(base, path) { |
Just go ahead and update the existing one. |
Refactored. |
Thanks for the great PR! |
Fixes #10657
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpm changeset
and following the prompts. Changesets that add features should beminor
and those that fix bugs should bepatch
. Please prefix changeset messages withfeat:
,fix:
, orchore:
.