mirror of
https://gh.catmak.name/https://github.com/mihomo-party-org/mihomo-party
synced 2025-12-27 05:00:30 +08:00
fix: prevent scientific notation parsing in YAML (#957)
This commit is contained in:
parent
fd708ec8bd
commit
73068f6544
@ -205,7 +205,10 @@ export async function setProfileStr(id: string, content: string): Promise<void>
|
||||
|
||||
export async function getProfile(id: string | undefined): Promise<IMihomoConfig> {
|
||||
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
|
||||
}
|
||||
|
||||
@ -50,7 +50,16 @@ export async function generateProfile(): Promise<void> {
|
||||
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)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user