From 061a94d5507922a3e6e30f4adf18ae92547a96dc Mon Sep 17 00:00:00 2001 From: Matthias Hannig Date: Sun, 16 Dec 2018 16:29:57 +0100 Subject: [PATCH] fixed is prefix method --- backend/utils.go | 4 +++- backend/utils_test.go | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/backend/utils.go b/backend/utils.go index 34e95b7..d637149 100644 --- a/backend/utils.go +++ b/backend/utils.go @@ -8,6 +8,8 @@ import ( "time" ) +var REGEX_MATCH_IP_PREFIX = regexp.MustCompile(`([a-f0-9/]+[\.:]*)+`) + /* Case Insensitive Contains */ @@ -42,7 +44,7 @@ func MaybePrefix(s string) bool { } // Test using regex - matches := regexp.MustCompile(`([a-f0-9/]+[\.:]?)+`).FindAllStringIndex(s, -1) + matches := REGEX_MATCH_IP_PREFIX.FindAllStringIndex(s, -1) if len(matches) == 1 { return true } diff --git a/backend/utils_test.go b/backend/utils_test.go index 1a53aaf..6ec9388 100644 --- a/backend/utils_test.go +++ b/backend/utils_test.go @@ -17,6 +17,7 @@ func TestMaybePrefix(t *testing.T) { }{ {"10.0.0", true}, {"23.42.11.42/23", true}, + {"fa42:2342::/32", true}, {"200", true}, {"2001:", true}, {"A", true},