diff --git a/shadowsocks-csharp/Controller/ShadowsocksController.cs b/shadowsocks-csharp/Controller/ShadowsocksController.cs index a86af97a..06bce1c4 100644 --- a/shadowsocks-csharp/Controller/ShadowsocksController.cs +++ b/shadowsocks-csharp/Controller/ShadowsocksController.cs @@ -5,6 +5,7 @@ using System.Net; using System.Net.Sockets; using System.Text; using System.Threading; +using System.Web; using Newtonsoft.Json; using Shadowsocks.Controller.Strategy; @@ -299,11 +300,15 @@ namespace Shadowsocks.Controller public static string GetQRCode(Server server) { - string parts = server.method; - if (server.auth) parts += "-auth"; - parts += ":" + server.password + "@" + server.server + ":" + server.server_port; + string tag = string.Empty; + string auth = server.auth ? "-auth" : string.Empty; + string parts = $"{server.method}{auth}:{server.password}@{server.server}:{server.server_port}"; string base64 = Convert.ToBase64String(Encoding.UTF8.GetBytes(parts)); - return "ss://" + base64; + if(!server.remarks.IsNullOrEmpty()) + { + tag = $"#{HttpUtility.UrlEncode(server.remarks, Encoding.UTF8)}"; + } + return $"ss://{base64}{tag}"; } public void UpdatePACFromGFWList() diff --git a/shadowsocks-csharp/Model/Server.cs b/shadowsocks-csharp/Model/Server.cs index 796a6c08..77fedba8 100755 --- a/shadowsocks-csharp/Model/Server.cs +++ b/shadowsocks-csharp/Model/Server.cs @@ -1,7 +1,7 @@ using System; using System.Text; using System.Text.RegularExpressions; - +using System.Web; using Shadowsocks.Controller; namespace Shadowsocks.Model @@ -10,7 +10,7 @@ namespace Shadowsocks.Model public class Server { public static readonly Regex - UrlFinder = new Regex("^(?i)ss://([A-Za-z0-9+-/=_]+)(#.+)?$", + UrlFinder = new Regex("^(?i)ss://([A-Za-z0-9+-/=_]+)(#(.+))?$", RegexOptions.IgnoreCase | RegexOptions.Compiled), DetailsParser = new Regex("^((?.+?)(?-auth)??:(?.*)@(?.+?)" + ":(?\\d+?))$", RegexOptions.Compiled | RegexOptions.IgnoreCase); @@ -79,9 +79,9 @@ namespace Shadowsocks.Model var match = UrlFinder.Match(ssURL); if (!match.Success) throw new FormatException(); var base64 = match.Groups[1].Value; - var tag = match.Groups[2].Value; + var tag = match.Groups[3].Value; if (!tag.IsNullOrEmpty()) - remarks = tag.Substring(1).Trim(); + remarks = HttpUtility.UrlDecode(tag, Encoding.UTF8); match = DetailsParser.Match(Encoding.UTF8.GetString(Convert.FromBase64String( base64.PadRight(base64.Length + (4 - base64.Length % 4) % 4, '=')))); method = match.Groups["method"].Value; diff --git a/shadowsocks-csharp/shadowsocks-csharp.csproj b/shadowsocks-csharp/shadowsocks-csharp.csproj index 8d59fe46..8379fe5f 100644 --- a/shadowsocks-csharp/shadowsocks-csharp.csproj +++ b/shadowsocks-csharp/shadowsocks-csharp.csproj @@ -81,6 +81,7 @@ +