fix(singbox): keep the ws path query when removing ed (#10548)

Removing "?ed=2048" from a WebSocket path also removed the '?', so
"/ws?ed=2048&key=value" was sent to sing-box as "/ws&key=value".
Match "ed" without the separator in front of it and trim the
leftover '&' or '?' instead.
This commit is contained in:
Aleksey Fedorov
2026-11-08 18:34:30 +10:00
committed by GitHub
parent 5ca37027fd
commit 73670c70d5
2 changed files with 29 additions and 6 deletions
@@ -542,7 +542,9 @@ public partial class CoreConfigSingboxService
// Parse eh and ed parameters from path using regex
if (!wsPath.IsNullOrEmpty())
{
var edRegex = new Regex(@"[?&]ed=(\d+)");
// Keep the '?' or '&' in front of "ed" out of the match, so removing it
// leaves "/ws?ed=2048&key=value" as "/ws?key=value", not "/ws&key=value".
var edRegex = new Regex(@"(?<=[?&])ed=(\d+)&?");
var edMatch = edRegex.Match(wsPath);
if (edMatch.Success && int.TryParse(edMatch.Groups[1].Value, out var edValue))
{
@@ -550,11 +552,7 @@ public partial class CoreConfigSingboxService
transport.early_data_header_name = "Sec-WebSocket-Protocol";
wsPath = edRegex.Replace(wsPath, "");
wsPath = wsPath.Replace("?&", "?");
if (wsPath.EndsWith('?'))
{
wsPath = wsPath.TrimEnd('?');
}
wsPath = wsPath.TrimEnd('&').TrimEnd('?');
}
var ehRegex = new Regex(@"[?&]eh=([^&]+)");