From 7d0414f8ca58efac02a42edba3cf3e927346b913 Mon Sep 17 00:00:00 2001 From: xream Date: Thu, 5 Sep 2024 17:39:42 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E4=BC=A0=E8=BE=93=E5=B1=82=20path=20?= =?UTF-8?q?=E5=BA=94=E4=B8=BA=E4=BB=A5=20/=20=E5=BC=80=E5=A4=B4=E7=9A=84?= =?UTF-8?q?=E5=AD=97=E7=AC=A6=E4=B8=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- backend/src/core/proxy-utils/index.js | 36 ++++++++++++++++++--------- 2 files changed, 25 insertions(+), 13 deletions(-) diff --git a/backend/package.json b/backend/package.json index 224ae70..3ff8488 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.14.379", + "version": "2.14.380", "description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and ShadowRocket.", "main": "src/main.js", "scripts": { diff --git a/backend/src/core/proxy-utils/index.js b/backend/src/core/proxy-utils/index.js index 4f2a4f0..57e0f88 100644 --- a/backend/src/core/proxy-utils/index.js +++ b/backend/src/core/proxy-utils/index.js @@ -313,6 +313,19 @@ function safeMatch(parser, line) { } } +function formatTransportPath(path) { + if (typeof path === 'string' || typeof path === 'number') { + path = String(path).trim(); + + if (path === '') { + return '/'; + } else if (!path.startsWith('/')) { + return '/' + path; + } + } + return path; +} + function lastParse(proxy) { if (proxy.interface) { proxy['interface-name'] = proxy.interface; @@ -341,6 +354,17 @@ function lastParse(proxy) { delete proxy['ws-headers']; } + const transportPath = proxy[`${proxy.network}-opts`]?.path; + + if (Array.isArray(transportPath)) { + proxy[`${proxy.network}-opts`].path = transportPath.map((item) => + formatTransportPath(item), + ); + } else if (transportPath != null) { + proxy[`${proxy.network}-opts`].path = + formatTransportPath(transportPath); + } + if (proxy.type === 'trojan') { if (proxy.network === 'tcp') { delete proxy.network; @@ -501,18 +525,6 @@ function lastParse(proxy) { proxy[`${proxy.network}-opts`].path = ['/']; } } - const transportPath = proxy[`${proxy.network}-opts`]?.path; - if (Array.isArray(transportPath)) { - transportPath.forEach((path, index) => { - if (!path.startsWith('/')) { - proxy[`${proxy.network}-opts`].path[index] = `/${path}`; - } - }); - } else if (transportPath) { - if (!transportPath.startsWith('/')) { - proxy[`${proxy.network}-opts`].path = `/${transportPath}`; - } - } if (['', 'off'].includes(proxy.sni)) { proxy['disable-sni'] = true; }