diff --git a/pkg/iplibrary/template.go b/pkg/iplibrary/template.go index e6ab7d5..01fae7a 100644 --- a/pkg/iplibrary/template.go +++ b/pkg/iplibrary/template.go @@ -38,7 +38,7 @@ func (this *Template) init() error { return keyword }) - reg, err := regexp.Compile("^(?U)" + template) + reg, err := regexp.Compile("^(?U)" + template + "\n?$") if err != nil { return err } diff --git a/pkg/iplibrary/template_test.go b/pkg/iplibrary/template_test.go index b4762a4..92ed22a 100644 --- a/pkg/iplibrary/template_test.go +++ b/pkg/iplibrary/template_test.go @@ -13,14 +13,15 @@ func TestNewTemplate(t *testing.T) { t.Fatal(err) } for _, s := range []string{ + "0.0.0.0|0.255.255.255|0|0|0|内网IP|内网IP", "42.0.32.0|42.0.63.255|中国|0|广东省|广州市|电信", "42.0.32.0|42.0.63.255|中国|0|广东省|广州市|电信\n123", "42.0.32.0|42.0.63.255|中国||广东省|广州市|电信", "42.0.32.0|42.0.63.255|中国|0||广州市|电信", "42.0.32.0|42.0.63.255|中国|0|广东省|广州市", } { - values, _ := template.Extract(s, []string{}) - t.Log(s, "=>\n", values) + values, ok := template.Extract(s, []string{}) + t.Log(ok, s, "=>\n", values) } }