Skip to content

Commit

Permalink
fix: 传输层 path 应为以 / 开头的字符串
Browse files Browse the repository at this point in the history
  • Loading branch information
xream committed Sep 5, 2024
1 parent bee1d62 commit 7d0414f
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 13 deletions.
2 changes: 1 addition & 1 deletion backend/package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
36 changes: 24 additions & 12 deletions backend/src/core/proxy-utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 7d0414f

Please sign in to comment.