mirror of
https://github.com/sub-store-org/Sub-Store.git
synced 2026-11-27 06:43:08 +00:00
fix(trojan): keep the URI name when there is no query string
The port check ran on the whole line, so with a #name and no ?query it did not see the port and appended :443 after the name: trojan://p@host:443#Node was named 'Node:443', and trojan://p@host#Node did not parse at all.
This commit is contained in:
1 parent
a6d09c7aaa
commit
24faf5e052
2 files changed
+38
-3
No files matched your search
@@ -2520,12 +2520,16 @@ function URI_Trojan() {
|
||||
};
|
||||
|
||||
const parse = (line) => {
|
||||
const matched = /^(trojan:\/\/.*?@.*?)(:(\d+))?\/?(\?.*?)?$/.exec(line);
|
||||
// Split off the name first: with a "#name" but no query string, the port
|
||||
// check below would not see the port and would append ":443" to the name.
|
||||
let [newLine, name] = line.split(/#(.+)/, 2);
|
||||
const matched = /^(trojan:\/\/.*?@.*?)(:(\d+))?\/?(\?.*?)?$/.exec(
|
||||
newLine,
|
||||
);
|
||||
const port = matched?.[2];
|
||||
if (!port) {
|
||||
line = line.replace(matched[1], `${matched[1]}:443`);
|
||||
newLine = newLine.replace(matched[1], `${matched[1]}:443`);
|
||||
}
|
||||
let [newLine, name] = line.split(/#(.+)/, 2);
|
||||
const parser = getTrojanURIParser();
|
||||
const proxy = parser.parse(newLine);
|
||||
if (isNotBlank(name)) {
|
||||
|
||||
@@ -699,6 +699,37 @@ describe('Proxy URI parser coverage', function () {
|
||||
);
|
||||
});
|
||||
|
||||
it('keeps the trojan name when there is no query string', function () {
|
||||
expectSubset(
|
||||
parseOne(
|
||||
'trojan://trojan-pass@trojan.example.com:8443#My%20Node',
|
||||
),
|
||||
{
|
||||
server: 'trojan.example.com',
|
||||
port: 8443,
|
||||
name: 'My Node',
|
||||
},
|
||||
);
|
||||
expectSubset(
|
||||
parseOne(
|
||||
'trojan://trojan-pass@trojan.example.com#Default%20Port',
|
||||
),
|
||||
{
|
||||
server: 'trojan.example.com',
|
||||
port: 443,
|
||||
name: 'Default Port',
|
||||
},
|
||||
);
|
||||
expectSubset(
|
||||
parseOne('trojan://trojan-pass@[2001:db8::2]#IPv6%20Name'),
|
||||
{
|
||||
server: '2001:db8::2',
|
||||
port: 443,
|
||||
name: 'IPv6 Name',
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it('does not double-decode Trojan path query values before extracting early data', function () {
|
||||
const proxy = parseOne(
|
||||
`trojan://trojan-pass@trojan-ws.example.com?type=ws&host=ws.example.com&path=${encodeURIComponent(
|
||||
|
||||
Reference in new issue
Block a user