feat: Hysteria2 端口跳跃支持范围格式, 先只做拆分兼容

This commit is contained in:
xream committed 2026-04-11 23:35:35 +08:00
1 parent 8c98f39824
commit de5fea225d
5 files changed
+127 -4

No files matched your search

+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "sub-store",
"version": "2.21.87",
"version": "2.21.88",
"description": "Advanced Subscription Manager for QX, Loon, Surge, Stash and Shadowrocket.",
"main": "src/main.js",
"scripts": {
+32
View File
@@ -400,6 +400,38 @@ function lastParse(proxy) {
if (typeof proxy.password === 'number') {
proxy.password = numberToString(proxy.password);
}
if (proxy['hop-interval'] != null) {
const hopInterval = `${proxy['hop-interval']}`.trim();
const hopIntervalRangeMatch = hopInterval.match(/^(\d+)\s*-\s*(\d+)$/);
if (hopIntervalRangeMatch) {
const hopIntervalMin = parseInt(hopIntervalRangeMatch[1], 10);
const hopIntervalMax = parseInt(hopIntervalRangeMatch[2], 10);
if (hopIntervalMin > 0 && hopIntervalMin <= hopIntervalMax) {
// 暂时只在统一收口阶段拆分 mihomo 的 hop-interval 区间写法,
// 不对其他客户端做进一步转换,等 mihomo / sing-box 新版覆盖率上来后再统一处理。
proxy['hop-interval'] = hopIntervalMin;
proxy['hop-interval-max'] = hopIntervalMax;
} else {
delete proxy['hop-interval'];
delete proxy['hop-interval-max'];
}
} else if (/^\d+$/.test(hopInterval)) {
const parsedHopInterval = parseInt(hopInterval, 10);
if (parsedHopInterval > 0) {
proxy['hop-interval'] = parsedHopInterval;
delete proxy['hop-interval-max'];
} else {
delete proxy['hop-interval'];
delete proxy['hop-interval-max'];
}
} else {
delete proxy['hop-interval'];
delete proxy['hop-interval-max'];
}
}
if (
['ss'].includes(proxy.type) &&
proxy.cipher === 'none' &&
@@ -1215,8 +1215,8 @@ function URI_Hysteria2() {
proxy['tls-fingerprint'] = params.pinSHA256;
let hop_interval = params['hop-interval'] || params['hop_interval'];
if (/^\d+$/.test(hop_interval)) {
proxy['hop-interval'] = parseInt(`${hop_interval}`, 10);
if (hop_interval != null) {
proxy['hop-interval'] = hop_interval;
}
let keepalive = params['keepalive'];
@@ -142,6 +142,66 @@ FINAL,DIRECT
});
});
it('splits mihomo hop-interval ranges for Clash-style object inputs', function () {
const proxy = parseOne(
JSON.stringify({
name: 'hy2-range-inline',
type: 'hysteria2',
server: 'hy2.example.com',
port: 443,
password: 'secret',
'hop-interval': '15-30',
}),
);
expectSubset(proxy, {
name: 'hy2-range-inline',
type: 'hysteria2',
'hop-interval': 15,
'hop-interval-max': 30,
});
});
it('drops invalid mihomo hop-interval values for Clash-style object inputs', function () {
const invalidHopIntervals = [
{ title: 'zero string', value: '0' },
{ title: 'zero number', value: 0 },
{ title: 'negative string', value: '-5' },
{ title: 'negative number', value: -5 },
{ title: 'decimal string', value: '15.5' },
{ title: 'decimal number', value: 15.5 },
{ title: 'comma list', value: '15,30' },
{ title: 'plain text', value: 'abc' },
{ title: 'empty string', value: '' },
{ title: 'blank string', value: ' ' },
{ title: 'zero-start range', value: '0-15' },
{ title: 'zero-end range', value: '15-0' },
{ title: 'reverse range', value: '30-15' },
{ title: 'multi-range', value: '15-30-45' },
{ title: 'double hyphen range', value: '15--30' },
{ title: 'boolean', value: true },
{ title: 'array', value: [15, 30] },
{ title: 'object', value: { min: 15, max: 30 } },
];
for (const { title, value } of invalidHopIntervals) {
const proxy = parseOne(
JSON.stringify({
name: `hy2-invalid-${title}`,
type: 'hysteria2',
server: 'hy2.example.com',
port: 443,
password: 'secret',
'hop-interval': value,
'hop-interval-max': 999,
}),
);
expect(proxy).to.not.have.property('hop-interval');
expect(proxy).to.not.have.property('hop-interval-max');
}
});
it('accepts every Clash-supported proxy type as inline objects', function () {
const supportedTypes = [
'tailscale',
@@ -185,4 +245,3 @@ FINAL,DIRECT
}
});
});
@@ -282,6 +282,38 @@ describe('Proxy URI parser coverage', function () {
expect(proxy.port).to.be.within(8443, 8445);
});
it('splits Hysteria2 URI hop-interval ranges during normalization', function () {
const proxy = parseOne(
'hy2://hy2-secret@hy2.example.com:443?hop-interval=15-30#Hy2%20Hop%20Range',
);
expectSubset(proxy, {
type: 'hysteria2',
name: 'Hy2 Hop Range',
server: 'hy2.example.com',
port: 443,
password: 'hy2-secret',
'hop-interval': 15,
'hop-interval-max': 30,
});
});
it('drops invalid Hysteria2 URI hop-interval values during normalization', function () {
const proxy = parseOne(
'hy2://hy2-secret@hy2.example.com:443?hop-interval=30-15#Hy2%20Invalid%20Hop',
);
expectSubset(proxy, {
type: 'hysteria2',
name: 'Hy2 Invalid Hop',
server: 'hy2.example.com',
port: 443,
password: 'hy2-secret',
});
expect(proxy).to.not.have.property('hop-interval');
expect(proxy).to.not.have.property('hop-interval-max');
});
it('parses Hysteria2 URIs with mport overrides', function () {
const proxy = parseOne(
'hy2://hy2-secret@hy2.example.com:443?mport=9000,9002-9004#Hy2%20Mport',