1
0
mirror of https://github.com/nitezs/sub2clash.git synced 2024-12-23 13:34:43 -05:00

fix: hy2 解析缺少 name 字段

This commit is contained in:
Nite07 2024-04-21 00:23:29 +08:00
parent faaf5c366a
commit aa9e102a81
3 changed files with 24 additions and 1 deletions

1
.gitignore vendored
View File

@ -1,7 +1,6 @@
.idea .idea
dist dist
subs subs
test
logs logs
sub2clash.db sub2clash.db
.env .env

View File

@ -38,6 +38,8 @@ func ParseHysteria2(proxy string) (model.Proxy, error) {
if strings.Contains(proxy, "#") { if strings.Contains(proxy, "#") {
splitResult := strings.Split(proxy, "#") splitResult := strings.Split(proxy, "#")
name, _ = url.QueryUnescape(splitResult[len(splitResult)-1]) name, _ = url.QueryUnescape(splitResult[len(splitResult)-1])
} else {
name = strings.Join(serverAndPort, ":")
} }
// 返回结果 // 返回结果
result := model.Proxy{ result := model.Proxy{

22
test/parser_test.go Normal file
View File

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