Skip to content

Commit da3d781

Browse files
authoredOct 21, 2023
fix: don't normalize non-html/non-http links (#3114)
1 parent a13f5cb commit da3d781

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed
 

‎src/client/theme-default/support/utils.ts

+9-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,17 @@ export function ensureStartingSlash(path: string): string {
2121
}
2222

2323
export function normalizeLink(url: string): string {
24-
if (isExternal(url)) return url
24+
const { pathname, search, hash, protocol } = new URL(url, 'http://a.com')
25+
26+
if (
27+
isExternal(url) ||
28+
url.startsWith('#') ||
29+
!protocol.startsWith('http') ||
30+
/\.(?!html|md)\w+($|\?)/i.test(url)
31+
)
32+
return url
2533

2634
const { site } = useData()
27-
const { pathname, search, hash } = new URL(url, 'http://a.com')
2835

2936
const normalizedPath =
3037
pathname.endsWith('/') || pathname.endsWith('.html')

‎src/node/markdown/plugins/link.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ export const linkPlugin = (
3838
if (
3939
// internal anchor links
4040
!url.startsWith('#') &&
41-
// mail links
42-
!url.startsWith('mailto:') &&
41+
// mail/custom protocol links
42+
new URL(url, 'http://a.com').protocol.startsWith('http') &&
4343
// links to files (other than html/md)
4444
!/\.(?!html|md)\w+($|\?)/i.test(url)
4545
) {

0 commit comments

Comments
 (0)
Please sign in to comment.