From 87c43fed361cda309e9f87801fe35e920ce50f2c Mon Sep 17 00:00:00 2001 From: xream Date: Sat, 11 Jul 2026 22:55:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20mihomo=20=E9=A2=84=E5=A4=84=E7=90=86?= =?UTF-8?q?=E5=99=A8=E6=94=AF=E6=8C=81=20proxies=20=E4=B8=BA=E7=A9=BA?= =?UTF-8?q?=E7=9A=84=E6=83=85=E5=86=B5,=20=E8=8B=A5=20proxies=20=E4=B8=8D?= =?UTF-8?q?=E5=90=88=E6=B3=95,=20=E5=A4=9A=E5=88=A4=E6=96=AD=E4=B8=80?= =?UTF-8?q?=E4=B8=8B=20proxy-groups=20=E6=98=AF=E5=90=A6=E4=B8=BA=E6=95=B0?= =?UTF-8?q?=E7=BB=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/package.json | 2 +- .../core/proxy-utils/preprocessors/index.js | 7 ++-- .../proxy-preprocessors/preprocessors.spec.js | 33 +++++++++++++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/backend/package.json b/backend/package.json index 12eb482e..5ebe6b82 100644 --- a/backend/package.json +++ b/backend/package.json @@ -1,6 +1,6 @@ { "name": "sub-store", - "version": "2.36.3", + "version": "2.36.4", "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/preprocessors/index.js b/backend/src/core/proxy-utils/preprocessors/index.js index 8bdfecc9..317d6a58 100644 --- a/backend/src/core/proxy-utils/preprocessors/index.js +++ b/backend/src/core/proxy-utils/preprocessors/index.js @@ -111,7 +111,10 @@ function Clash() { const test = function (raw) { if (!/proxies/.test(raw)) return false; const content = safeLoad(raw); - return content.proxies && Array.isArray(content.proxies); + return ( + Array.isArray(content.proxies) || + Array.isArray(content['proxy-groups']) + ); }; const parse = function (raw, includeProxies) { // Clash YAML format @@ -121,7 +124,7 @@ function Clash() { const { proxies } = safeLoad(afterReplace); return ( (includeProxies ? 'proxies:\n' : '') + - proxies + (Array.isArray(proxies) ? proxies : []) .map((p) => { return `${includeProxies ? ' - ' : ''}${JSON.stringify( p, diff --git a/backend/src/test/proxy-preprocessors/preprocessors.spec.js b/backend/src/test/proxy-preprocessors/preprocessors.spec.js index 83546d6d..ab3164f9 100644 --- a/backend/src/test/proxy-preprocessors/preprocessors.spec.js +++ b/backend/src/test/proxy-preprocessors/preprocessors.spec.js @@ -114,6 +114,39 @@ describe('Proxy preprocessors', function () { }); describe('Clash preprocessor', function () { + it('accepts an empty proxies field', function () { + const processor = getPreprocessor('Clash Pre-processor'); + const raw = `proxies: + +proxy-groups: + - name: Select + type: select + proxies: + - DIRECT +`; + + expect(processor.test(raw)).to.equal(true); + expect(processor.parse(raw)).to.equal(''); + expect(processor.parse(raw, true)).to.equal('proxies:\n'); + }); + + it('accepts a proxy groups array when proxies is invalid', function () { + const processor = getPreprocessor('Clash Pre-processor'); + const raw = `proxies: invalid +proxy-groups: + - test +`; + + expect(processor.test(raw)).to.equal(true); + expect(processor.parse(raw)).to.equal(''); + expect( + processor.test('proxies: invalid\nproxy-groups: {}'), + ).to.equal(false); + expect(processor.test('proxies: invalid\nrules: []')).to.equal( + false, + ); + }); + it('converts clash yaml proxies into json lines', function () { const processor = getPreprocessor('Clash Pre-processor'); const raw = `proxies: