mirror of
https://github.com/sub-store-org/Sub-Store.git
synced 2026-11-28 23:40:30 +00:00
feat: mihomo 预处理器支持 proxies 为空的情况, 若 proxies 不合法, 多判断一下 proxy-groups 是否为数组
This commit is contained in:
3 files changed
+39
-3
No files matched your search
@@ -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",
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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:
|
||||
|
||||
Reference in new issue
Block a user