fix: keep malformed URLs during normalization (#49870)

This commit is contained in:
chen zhihao authored and GitHub committed 2026-09-04 17:13:08 +02:00
1 parent 9652409093
commit c5e24196b1
3 files changed
+27 -2

No files matched your search

+11 -2
View File
@@ -39,9 +39,18 @@ export function isURI(string: string): boolean {
}
export function normalizeURL(url: string): string {
const normalized = normalizeUrl(url, { stripWWW: false })
let normalized: string
try {
normalized = normalizeUrl(url, { stripWWW: false })
} catch {
return url.replace(/\s/g, '+')
}
return decodeURIComponent(normalized).replace(/\s/g, '+').toString()
try {
return decodeURIComponent(normalized).replace(/\s/g, '+')
} catch {
return normalized.replace(/\s/g, '+')
}
}
export function truncate(string: string, limit: number = 100) {