From 1e5ba57de372bd13b0231e969dbb62a7fa8d7b52 Mon Sep 17 00:00:00 2001 From: Liang-Chi Hsieh Date: Tue, 12 Nov 2013 10:53:34 +0800 Subject: [PATCH 1/2] fix nameserver regex. --- utils/utils.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/utils.go b/utils/utils.go index 03fdc1987a..6b1a70df41 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -944,7 +944,7 @@ func StripComments(input []byte, commentMarker []byte) []byte { func GetNameserversAsCIDR(resolvConf []byte) []string { var parsedResolvConf = StripComments(resolvConf, []byte("#")) nameservers := []string{} - re := regexp.MustCompile(`^\s*nameserver\s*(([0-9]\.){3}([0-9]))\s*$`) + re := regexp.MustCompile(`^\s*nameserver\s*(([0-9]+\.){3}([0-9]+))\s*$`) for _, line := range bytes.Split(parsedResolvConf, []byte("\n")) { var ns = re.FindSubmatch(line) if len(ns) > 0 { From 879aa29cb09c641bbd510eed03647f8f85f0d559 Mon Sep 17 00:00:00 2001 From: Liang-Chi Hsieh Date: Tue, 12 Nov 2013 18:18:30 +0800 Subject: [PATCH 2/2] modify test of GetNameserversAsCIDR for its regex change. --- utils/utils_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/utils_test.go b/utils/utils_test.go index a6fcbf24bb..09b15c73bc 100644 --- a/utils/utils_test.go +++ b/utils/utils_test.go @@ -481,12 +481,12 @@ func TestParsePortMapping(t *testing.T) { func TestGetNameserversAsCIDR(t *testing.T) { for resolv, result := range map[string][]string{` nameserver 1.2.3.4 -nameserver 4.3.2.1 -search example.com`: {"1.2.3.4/32", "4.3.2.1/32"}, +nameserver 40.3.200.10 +search example.com`: {"1.2.3.4/32", "40.3.200.10/32"}, `search example.com`: {}, `nameserver 1.2.3.4 search example.com -nameserver 4.3.2.1`: {"1.2.3.4/32", "4.3.2.1/32"}, +nameserver 4.30.20.100`: {"1.2.3.4/32", "4.30.20.100/32"}, ``: {}, ` nameserver 1.2.3.4 `: {"1.2.3.4/32"}, `search example.com