修复IP库模板可能无法正确解析数据的问题

This commit is contained in:
刘祥超
2023-03-29 20:06:56 +08:00
parent 67aafeee30
commit 22bf132efb
2 changed files with 14 additions and 1 deletions

View File

@@ -38,7 +38,7 @@ func (this *Template) init() error {
return keyword
})
reg, err := regexp.Compile(template)
reg, err := regexp.Compile("^(?U)" + template)
if err != nil {
return err
}

View File

@@ -23,3 +23,16 @@ func TestNewTemplate(t *testing.T) {
t.Log(s, "=>\n", values)
}
}
func TestNewTemplate2(t *testing.T) {
template, err := iplibrary.NewTemplate("${any},${any},${ipFrom},${ipTo},${country},${province},${city},${town},${provider},${any},${any}")
if err != nil {
t.Fatal(err)
}
for _, s := range []string{
"22723584,22723839,1.90.188.0,1.90.188.255,中国,北京,北京,房山,歌华有线,102400,010,城域网",
} {
values, _ := template.Extract(s, []string{})
t.Log(s, "=>\n", values)
}
}