Skip to content

Commit

Permalink
fix!: hasProtocol additional protocols (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
divine committed Mar 15, 2022
1 parent 2960f2a commit d66cb64
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = /\/$|\/\?/
Expand Down
7 changes: 5 additions & 2 deletions test/utilities.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit d66cb64

Please sign in to comment.