fix(editor): prevent errors from isStrictUrl (#9419)

Closes: [BS-2277](https://linear.app/affine-design/issue/BS-2277/typeerror-failed-to-construct-url-invalid-url)
This commit is contained in:
Saul-Mirone
2024-12-30 02:45:59 +00:00
parent e630290e7c
commit 6b1865ff92

View File

@@ -130,14 +130,17 @@ function isCommonTLD(url: URL) {
* Assuming the user will input anything, we need to check rigorously.
*/
export function isStrictUrl(str: string) {
if (!isValidUrl(str)) {
try {
if (!isValidUrl(str)) {
return false;
}
const url = new URL(normalizeUrl(str));
return isCommonTLD(url);
} catch {
return false;
}
const url = new URL(normalizeUrl(str));
if (isCommonTLD(url)) {
return true;
}
return false;
}
export function isUrlInClipboard(clipboardData: DataTransfer) {