diff --git a/src/utils.ts b/src/utils.ts index 3f324936..2fd9c25e 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -8,7 +8,7 @@ export function isRelative (inputStr: string) { } export function hasProtocol (inputStr: string, acceptProtocolRelative = false): boolean { - return /^\w+:\/\/.+/.test(inputStr) || (acceptProtocolRelative && /^\/\/[^/]+/.test(inputStr)) + return /^\w+:(\/\/)?.+/.test(inputStr) || (acceptProtocolRelative && /^\/\/[^/]+/.test(inputStr)) } const TRAILING_SLASH_RE = /\/$|\/\?/ diff --git a/test/utilities.test.ts b/test/utilities.test.ts index f4714a97..e1f5f4d3 100644 --- a/test/utilities.test.ts +++ b/test/utilities.test.ts @@ -6,10 +6,13 @@ describe('hasProtocol', () => { { input: '//', out: [false, false] }, { input: '///', out: [false, false] }, { input: '//test.com', out: [true, false] }, - { input: 'https://', out: [false, false] }, + { input: 'https://', out: [true, true] }, { input: 'https://test.com', out: [true, true] }, { input: '/test', out: [false, false] }, - { input: 'file:///home/user', out: [true, true] } + { input: 'file:///home/user', out: [true, true] }, + { input: 'tel:', out: [false, false] }, + { input: 'tel:123456', out: [true, true] }, + { input: 'mailto:support@example.com', out: [true, true] } ] for (const t of tests) {