fix: 传输层 path 应为以 / 开头的字符串

This commit is contained in:
xream 2024-09-05 17:39:42 +08:00
parent bee1d62a1a
commit 7d0414f8ca
No known key found for this signature in database
GPG Key ID: 1D2C5225471789F9
2 changed files with 25 additions and 13 deletions

View File

@ -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": {

View File

@ -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;
}