diff --git a/packages/core/src/utils/isAbsoluteUrl.test.ts b/packages/core/src/utils/isAbsoluteUrl.test.ts index 30cab2c..f3f39e6 100644 --- a/packages/core/src/utils/isAbsoluteUrl.test.ts +++ b/packages/core/src/utils/isAbsoluteUrl.test.ts @@ -13,8 +13,8 @@ describe('utils::isAbsoluteUrl', () => { expect(isAbsoluteUrl('!valid://example.com/')).toBe(false); }); - it('should return true if URL is protocol-relative', () => { - expect(isAbsoluteUrl('//example.com/')).toBe(true); + it('should return false if URL is protocol-relative', () => { + expect(isAbsoluteUrl('//example.com/')).toBe(false); }); it('should return false if URL is relative', () => { diff --git a/packages/core/src/utils/isAbsoluteUrl.ts b/packages/core/src/utils/isAbsoluteUrl.ts index 3f96726..78548d1 100644 --- a/packages/core/src/utils/isAbsoluteUrl.ts +++ b/packages/core/src/utils/isAbsoluteUrl.ts @@ -1,4 +1,7 @@ export const isAbsoluteUrl = (url: string) => { + // A URL is considered absolute if it begins with "://". + // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed + // by any combination of letters, digits, plus, period, or hyphen. // eslint-disable-next-line regexp/no-unused-capturing-group - return /^([a-z][\d+.a-z-]*:)?\/\//i.test(url); + return /^([a-z][\d+.a-z-]*:)\/\//i.test(url); };