fix: remove comments from svg icons to prevent front-end crashes. fixer #2093

This commit is contained in:
huzibaca 2024-11-25 01:58:02 +08:00
parent e3800a575f
commit 746763ed34
No known key found for this signature in database
GPG Key ID: D4364EE4851DC302

View File

@ -64,10 +64,15 @@ export const TestViewer = forwardRef<TestViewerRef, Props>((props, ref) => {
try { try {
if (!form.name) throw new Error("`Name` should not be null"); if (!form.name) throw new Error("`Name` should not be null");
if (!form.url) throw new Error("`Url` should not be null"); if (!form.url) throw new Error("`Url` should not be null");
let newList; let newList;
let uid; let uid;
if (form.icon && form.icon.startsWith("<svg")) { if (form.icon && form.icon.startsWith("<svg")) {
// 移除 icon 中的注释
if (form.icon) {
form.icon = form.icon.replace(/<!--[\s\S]*?-->/g, "");
}
const doc = new DOMParser().parseFromString( const doc = new DOMParser().parseFromString(
form.icon, form.icon,
"image/svg+xml", "image/svg+xml",