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: