From 51d169d2e8e5cbd670d234f90625de61ff6e0032 Mon Sep 17 00:00:00 2001 From: xmk23333 Date: Tue, 16 Dec 2025 15:36:48 +0800 Subject: [PATCH] feat: add HTML detection and error handling for profile parsing --- src/main/config/profile.ts | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/main/config/profile.ts b/src/main/config/profile.ts index 88dfb4e..e03fd22 100644 --- a/src/main/config/profile.ts +++ b/src/main/config/profile.ts @@ -306,9 +306,28 @@ export async function setProfileStr(id: string, content: string): Promise export async function getProfile(id: string | undefined): Promise { const profile = await getProfileStr(id) - let result = parse(profile) - if (typeof result !== 'object') result = {} - return result as IMihomoConfig + + // 检测是否为 HTML 内容(订阅返回错误页面) + const trimmed = profile.trim() + if ( + trimmed.startsWith(']*>/i.test(trimmed.slice(0, 500)) + ) { + throw new Error( + `Profile "${id}" contains HTML instead of YAML. The subscription may have returned an error page. Please re-import or update the subscription.` + ) + } + + try { + let result = parse(profile) + if (typeof result !== 'object') result = {} + return result as IMihomoConfig + } catch (e) { + const msg = e instanceof Error ? e.message : String(e) + throw new Error(`Failed to parse profile "${id}": ${msg}`) + } } // attachment;filename=xxx.yaml; filename*=UTF-8''%xx%xx%xx