From e73999680b7273de03a6202ed0177160d2f6c5f1 Mon Sep 17 00:00:00 2001 From: Miek Gieben Date: Sat, 25 Jan 2020 17:04:16 +0100 Subject: [PATCH] more strict with whitespace Signed-off-by: Miek Gieben --- plugin/traffic/setup.go | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/plugin/traffic/setup.go b/plugin/traffic/setup.go index 9b0f70039..2bdca7f27 100644 --- a/plugin/traffic/setup.go +++ b/plugin/traffic/setup.go @@ -141,13 +141,37 @@ func parseLocality(s string) ([]xds.Locality, error) { default: return nil, fmt.Errorf("too many location specifiers: %q", s) case 1: - locs = append(locs, xds.Locality{Region: l[0]}) + l0 := strings.TrimSpace(l[0]) + if l0 == "" { + return nil, fmt.Errorf("empty location specifer: %q", l[0]) + } + locs = append(locs, xds.Locality{Region: l0}) continue case 2: - locs = append(locs, xds.Locality{Region: l[0], Zone: l[1]}) + l0 := strings.TrimSpace(l[0]) + if l0 == "" { + return nil, fmt.Errorf("empty location specifer: %q", l[0]) + } + l1 := strings.TrimSpace(l[1]) + if l1 == "" { + return nil, fmt.Errorf("empty location specifer: %q", l[1]) + } + locs = append(locs, xds.Locality{Region: l0, Zone: l1}) continue case 3: - locs = append(locs, xds.Locality{Region: l[0], Zone: l[1], SubZone: l[2]}) + l0 := strings.TrimSpace(l[0]) + if l0 == "" { + return nil, fmt.Errorf("empty location specifer: %q", l[0]) + } + l1 := strings.TrimSpace(l[1]) + if l1 == "" { + return nil, fmt.Errorf("empty location specifer: %q", l[1]) + } + l2 := strings.TrimSpace(l[2]) + if l2 == "" { + return nil, fmt.Errorf("empty location specifer: %q", l[2]) + } + locs = append(locs, xds.Locality{Region: l0, Zone: l1, SubZone: l2}) continue }