diff --git a/backend/package.json b/backend/package.json index 4a248994..7353dfd9 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.36.20", + "version": "2.36.21", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.", "main": "src/main.js", "packageManager": "pnpm@11.0.9", diff --git a/backend/src/core/proxy-utils/index.js b/backend/src/core/proxy-utils/index.js index e94c30e3..30b4f77e 100644 --- a/backend/src/core/proxy-utils/index.js +++ b/backend/src/core/proxy-utils/index.js @@ -719,6 +719,33 @@ function formatTransportPath(path) { } function lastParse(proxy) { + // normalize keys to lowercase for all -opts keys and their subkeys + // 通常来说够用了, 在重构之前暂不考虑引入更复杂的逻辑 + const hasOwn = (value, key) => + Object.prototype.hasOwnProperty.call(value, key); + const normalizeOpts = (value) => { + if (!value || typeof value !== 'object' || Array.isArray(value)) return; + for (const key of Object.keys(value)) { + const normalizedKey = key.toLowerCase(); + if (key !== normalizedKey) { + if (!hasOwn(value, normalizedKey)) { + value[normalizedKey] = value[key]; + } + delete value[key]; + } + } + }; + for (const key of Object.keys(proxy)) { + const normalizedKey = key.toLowerCase(); + if (!normalizedKey.endsWith('-opts')) continue; + if (key !== normalizedKey) { + if (!hasOwn(proxy, normalizedKey)) { + proxy[normalizedKey] = proxy[key]; + } + delete proxy[key]; + } + normalizeOpts(proxy[normalizedKey]); + } proxy.udp = ![false, 0, '0', 'false', 'off'].includes( typeof proxy.udp === 'string' ? proxy.udp.toLowerCase() : proxy.udp, );