From 73068f65440049571223e4ecc6aa5e4fdf75e1c1 Mon Sep 17 00:00:00 2001 From: Memory <134070804+Memory2314@users.noreply.github.com> Date: Fri, 15 Aug 2025 13:24:44 +0800 Subject: [PATCH] fix: prevent scientific notation parsing in YAML (#957) --- src/main/config/profile.ts | 5 ++++- src/main/core/factory.ts | 11 ++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/main/config/profile.ts b/src/main/config/profile.ts index 2e0bcd1..393d0ab 100644 --- a/src/main/config/profile.ts +++ b/src/main/config/profile.ts @@ -205,7 +205,10 @@ export async function setProfileStr(id: string, content: string): Promise export async function getProfile(id: string | undefined): Promise { const profile = await getProfileStr(id) - let result = yaml.parse(profile, { merge: true }) || {} + + // 替换 防止错误使用科学记数法解析 + const patchedProfile = profile.replace(/(\w+:\s*)(\d+E\d+)(\s|$)/gi, '$1"$2"$3') + let result = yaml.parse(patchedProfile, { merge: true }) || {} if (typeof result !== 'object') result = {} return result } diff --git a/src/main/core/factory.ts b/src/main/core/factory.ts index 3e3979d..a5bb90c 100644 --- a/src/main/core/factory.ts +++ b/src/main/core/factory.ts @@ -50,7 +50,16 @@ export async function generateProfile(): Promise { profile['log-level'] = 'info' } runtimeConfig = profile - runtimeConfigStr = yaml.stringify(profile) + + // 先正常生成 YAML 字符串 + let yamlStr = yaml.stringify(profile) + // 还原科学记数法的引号 + yamlStr = yamlStr.replace( + /(\w+:\s*)"(\d+E\d+)"(\s|$)/gi, + '$1$2$3' + ) + runtimeConfigStr = yamlStr + if (diffWorkDir) { await prepareProfileWorkDir(current) }