From 129e20d7139d0158d6232a2b6b324a5589b0e765 Mon Sep 17 00:00:00 2001 From: Srinikitha Kondreddy Date: Wed, 9 Oct 2024 11:34:54 +0200 Subject: [PATCH] feat: add validation for application name (#5123) * feat: add validation for application name * improve error message --------- Co-authored-by: Oliver Feldmann --- pkg/transportrequest/cts/upload.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pkg/transportrequest/cts/upload.go b/pkg/transportrequest/cts/upload.go index fb22b4260e..a50458df70 100644 --- a/pkg/transportrequest/cts/upload.go +++ b/pkg/transportrequest/cts/upload.go @@ -2,10 +2,12 @@ package cts import ( "fmt" + "regexp" + "strings" + "github.com/SAP/jenkins-library/pkg/command" "github.com/SAP/jenkins-library/pkg/log" "github.com/SAP/jenkins-library/pkg/piperutils" - "strings" ) type fileUtils interface { @@ -60,6 +62,7 @@ const ( abapUserKey = "ABAP_USER" abapPasswordKey = "ABAP_PASSWORD" defaultConfigFileName = "ui5-deploy.yaml" + pattern = "^[a-zA-Z0-9_]+$" ) // WithConnection ... @@ -189,6 +192,10 @@ func getFioriDeployStatement( log.Entry().Debug("No application package found in piper config.") } if len(app.Name) > 0 { + re := regexp.MustCompile(pattern) + if !re.MatchString(app.Name) { + fmt.Errorf("application name '%s' contains spaces or special characters. It is not according to the '%s'", app.Name, pattern) + } log.Entry().Debugf("application name '%s' used from piper config", app.Name) cmd = append(cmd, "--name", app.Name) } else {