Skip to content

Commit 565ac2c

Browse files
authored
fix: error when invalid iframe in markdown (#5985)
1 parent 7d6f77b commit 565ac2c

1 file changed

Lines changed: 16 additions & 14 deletions

File tree

packages/utils/parse.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,25 @@ export const configuredXss = new FilterXSS({
4949
},
5050
]
5151

52-
const url = new URL(value)
53-
54-
for (const source of allowedSources) {
55-
if (!source.url.test(url.href)) {
56-
continue
57-
}
52+
try {
53+
const url = new URL(value)
5854

59-
const newSearchParams = new URLSearchParams(url.searchParams)
60-
url.searchParams.forEach((value, key) => {
61-
if (!source.allowedParameters.some((param) => param.test(`${key}=${value}`))) {
62-
newSearchParams.delete(key)
55+
for (const source of allowedSources) {
56+
if (!source.url.test(url.href)) {
57+
continue
6358
}
64-
})
6559

66-
url.search = newSearchParams.toString()
67-
return `${name}="${escapeAttrValue(url.toString())}"`
68-
}
60+
const newSearchParams = new URLSearchParams(url.searchParams)
61+
url.searchParams.forEach((value, key) => {
62+
if (!source.allowedParameters.some((param) => param.test(`${key}=${value}`))) {
63+
newSearchParams.delete(key)
64+
}
65+
})
66+
67+
url.search = newSearchParams.toString()
68+
return `${name}="${escapeAttrValue(url.toString())}"`
69+
}
70+
} catch {}
6971
}
7072

7173
// For Highlight.JS

0 commit comments

Comments
 (0)