From d66cb646c3a63dc747397c3d1e8b2bd3eed13d7f Mon Sep 17 00:00:00 2001 From: Divine <48183131+divine@users.noreply.github.com> Date: Tue, 15 Mar 2022 23:29:51 +0300 Subject: [PATCH] fix!: hasProtocol additional protocols (#46) --- src/utils.ts | 2 +- test/utilities.test.ts | 7 +++++-- 2 files changed, 6 insertions(+), 3 deletions(-) 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) {