Skip to content

Commit b69d3b3

Browse files
authored
Merge branch 'main' into normalizeRoutePath
2 parents 7374e36 + 8b1ab67 commit b69d3b3

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

packages/shared/src/utils/isLinkWithProtocol.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
* Determine a link has protocol or not
33
*/
44
export const isLinkWithProtocol = (link: string): boolean =>
5-
/^[a-z][a-z0-9+.-]*:/.test(link)
5+
/^[a-z][a-z0-9+.-]*:/.test(link) || link.startsWith('//')

packages/shared/tests/isLinkWithProtocol.spec.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,25 @@ import { expect, it } from 'vitest'
22
import { isLinkWithProtocol } from '../src/index.js'
33

44
const testCases: [string, ReturnType<typeof isLinkWithProtocol>][] = [
5+
// with protocol
56
['ftp://foobar.com', true],
67
['ms-windows-store://home', true],
78
['mailto:foobar', true],
89
['tel:foobar', true],
910
['https://foobar.com', true],
1011
['http://foobar.com', true],
12+
['//foobar.com', true],
13+
14+
// hostname
1115
['foobar.com', false],
16+
17+
// pathname
1218
['/foo/bar', false],
19+
20+
// relative path
1321
['../foo/bar', false],
14-
['//foobar.com', false],
22+
['./foo/bar', false],
23+
['foo/bar', false],
1524
]
1625

1726
testCases.forEach(([source, expected]) => {

0 commit comments

Comments
 (0)