internal/config: correctly set Quota.AcceptedURLs

Parse the env var value carefully. In particular, an empty env var means
"accept nothing", not "accept the empty string".

Fixes b/157403867.

Change-Id: I67d98da0c756af7517492e3d904d22fe64136113
Reviewed-on: https://team-review.git.corp.google.com/c/golang/discovery/+/766370
CI-Result: Cloud Build <devtools-proctor-result-processor@system.gserviceaccount.com>
Reviewed-by: Robert Findley <rfindley@google.com>
diff --git a/internal/config/config.go b/internal/config/config.go
index eb5b48b..5c4c252 100644
--- a/internal/config/config.go
+++ b/internal/config/config.go
@@ -303,9 +303,8 @@
 		Burst:        20,
 		MaxEntries:   1000,
 		RecordOnly:   func() *bool { t := true; return &t }(),
-		AcceptedURLs: strings.Split(GetEnv("GO_DISCOVERY_ACCEPTED_LIST", ""), ","),
+		AcceptedURLs: parseCommaList(GetEnv("GO_DISCOVERY_ACCEPTED_LIST", "")),
 	}
-
 	cfg.UseProfiler = os.Getenv("GO_DISCOVERY_USE_PROFILER") == "TRUE"
 
 	// If GO_DISCOVERY_CONFIG_OVERRIDE is set, it should point to a file
@@ -423,3 +422,14 @@
 	}
 	return string(bytes), nil
 }
+
+func parseCommaList(s string) []string {
+	var a []string
+	for _, p := range strings.Split(s, ",") {
+		p = strings.TrimSpace(p)
+		if p != "" {
+			a = append(a, p)
+		}
+	}
+	return a
+}
diff --git a/internal/config/config_test.go b/internal/config/config_test.go
index 76158c4..6a51849 100644
--- a/internal/config/config_test.go
+++ b/internal/config/config_test.go
@@ -77,3 +77,21 @@
 		t.Errorf("mismatch (-want, +got):\n%s", diff)
 	}
 }
+
+func TestParseCommaList(t *testing.T) {
+	for _, test := range []struct {
+		in   string
+		want []string
+	}{
+		{"", nil},
+		{"foo", []string{"foo"}},
+		{"foo,bar", []string{"foo", "bar"}},
+		{" foo, bar ", []string{"foo", "bar"}},
+		{",, ,foo ,  , bar,,,", []string{"foo", "bar"}},
+	} {
+		got := parseCommaList(test.in)
+		if !cmp.Equal(got, test.want) {
+			t.Errorf("%q: got %#v, want %#v", test.in, got, test.want)
+		}
+	}
+}