diff --git a/internal/ingress/annotations/parser/main.go b/internal/ingress/annotations/parser/main.go index 2012354dcd..d4a7d9ebd7 100644 --- a/internal/ingress/annotations/parser/main.go +++ b/internal/ingress/annotations/parser/main.go @@ -19,6 +19,7 @@ package parser import ( "fmt" "strconv" + "strings" extensions "k8s.io/api/extensions/v1beta1" @@ -52,11 +53,12 @@ func (a ingAnnotations) parseBool(name string) (bool, error) { func (a ingAnnotations) parseString(name string) (string, error) { val, ok := a[name] if ok { - if len(val) == 0 { + s := normalizeString(val) + if len(s) == 0 { return "", errors.NewInvalidAnnotationContent(name, val) } - return val, nil + return s, nil } return "", errors.ErrMissingAnnotations } @@ -119,3 +121,12 @@ func GetIntAnnotation(name string, ing *extensions.Ingress) (int, error) { func GetAnnotationWithPrefix(suffix string) string { return fmt.Sprintf("%v/%v", AnnotationsPrefix, suffix) } + +func normalizeString(input string) string { + trimmedContent := []string{} + for _, line := range strings.Split(input, "\n") { + trimmedContent = append(trimmedContent, strings.TrimSpace(line)) + } + + return strings.Join(trimmedContent, "\n") +} diff --git a/internal/ingress/annotations/parser/main_test.go b/internal/ingress/annotations/parser/main_test.go index 6b6365a96c..58020581ed 100644 --- a/internal/ingress/annotations/parser/main_test.go +++ b/internal/ingress/annotations/parser/main_test.go @@ -89,9 +89,17 @@ func TestGetStringAnnotation(t *testing.T) { exp string expErr bool }{ - {"valid - A", "string", "A", "A", false}, - {"valid - B", "string", "B", "B", false}, - {"empty", "string", "", "", true}, + {"valid - A", "string", "A ", "A", false}, + {"valid - B", "string", " B", "B", false}, + {"empty", "string", " ", "", true}, + {"valid multiline", "string", ` + rewrite (?i)/arcgis/rest/services/Utilities/Geometry/GeometryServer(.*)$ /arcgis/rest/services/Utilities/Geometry/GeometryServer$1 break; + rewrite (?i)/arcgis/services/Utilities/Geometry/GeometryServer(.*)$ /arcgis/services/Utilities/Geometry/GeometryServer$1 break; + `, ` +rewrite (?i)/arcgis/rest/services/Utilities/Geometry/GeometryServer(.*)$ /arcgis/rest/services/Utilities/Geometry/GeometryServer$1 break; +rewrite (?i)/arcgis/services/Utilities/Geometry/GeometryServer(.*)$ /arcgis/services/Utilities/Geometry/GeometryServer$1 break; +`, + false}, } data := map[string]string{}