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)) +}