From 97bec9183a09ccfe29f9509954ff923068fd7fdf Mon Sep 17 00:00:00 2001 From: pillarcoin <6373858+liangyi9812@users.noreply.github.com> Date: Fri, 11 Oct 2024 19:10:02 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20clash=20=E9=85=8D=E7=BD=AE=E4=B8=AD=20VL?= =?UTF-8?q?ESS=20=E8=8A=82=E7=82=B9=E7=9A=84=20short-id=20=E5=80=BC?= =?UTF-8?q?=E8=A2=AB=E9=94=99=E8=AF=AF=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/proxy-utils/preprocessors/index.js | 24 ++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/backend/src/core/proxy-utils/preprocessors/index.js b/backend/src/core/proxy-utils/preprocessors/index.js index d570120..d2fb84c 100644 --- a/backend/src/core/proxy-utils/preprocessors/index.js +++ b/backend/src/core/proxy-utils/preprocessors/index.js @@ -50,10 +50,32 @@ function Clash() { }; const parse = function (raw) { // Clash YAML format + + // 防止 VLESS节点 reality-opts 选项中的 short-id 被解析成 Infinity + // 匹配 short-id 冒号后面的值(包含空格和引号) + const afterReplace = raw.replace( + /short-id:([ ]*[^,\n}]*)/g, + (matched, value) => { + const afterTrim = value.trim(); + + // 为空 + if (!afterTrim || afterTrim === '') { + return 'short-id: ""' + } + + // 是否被引号包裹 + if (/^(['"]).*\1$/.test(afterTrim)) { + return `short-id: ${afterTrim}`; + } else { + return `short-id: "${afterTrim}"` + } + } + ); + const { proxies, 'global-client-fingerprint': globalClientFingerprint, - } = safeLoad(raw); + } = safeLoad(afterReplace); return proxies .map((p) => { // https://github.com/MetaCubeX/mihomo/blob/Alpha/docs/config.yaml#L73C1-L73C26