From aa9e102a8191b6082adcc515e1095d49be42b443 Mon Sep 17 00:00:00 2001 From: Nite07 Date: Sun, 21 Apr 2024 00:23:29 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20hy2=20=E8=A7=A3=E6=9E=90=E7=BC=BA?= =?UTF-8?q?=E5=B0=91=20name=20=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 - parser/hysteria2.go | 2 ++ test/parser_test.go | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 test/parser_test.go diff --git a/.gitignore b/.gitignore index 4d3cfdd..dc28154 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ .idea dist subs -test logs sub2clash.db .env diff --git a/parser/hysteria2.go b/parser/hysteria2.go index 9e0bf2e..39343e6 100644 --- a/parser/hysteria2.go +++ b/parser/hysteria2.go @@ -38,6 +38,8 @@ func ParseHysteria2(proxy string) (model.Proxy, error) { if strings.Contains(proxy, "#") { splitResult := strings.Split(proxy, "#") name, _ = url.QueryUnescape(splitResult[len(splitResult)-1]) + } else { + name = strings.Join(serverAndPort, ":") } // θΏ”ε›žη»“ζžœ result := model.Proxy{ diff --git a/test/parser_test.go b/test/parser_test.go new file mode 100644 index 0000000..fa055bb --- /dev/null +++ b/test/parser_test.go @@ -0,0 +1,22 @@ +package test + +import ( + "sub2clash/parser" + "testing" + + "gopkg.in/yaml.v3" +) + +func TestHy2Parser(t *testing.T) { + res, err := parser.ParseHysteria2("hysteria2://letmein@example.com/?insecure=1&obfs=salamander&obfs-password=gawrgura&pinSHA256=deadbeef&sni=real.example.com") + if err != nil { + t.Log(err.Error()) + t.Fail() + } + bytes, err := yaml.Marshal(res) + if err != nil { + t.Log(err.Error()) + t.Fail() + } + t.Log(string(bytes)) +}