You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by GitBox <gi...@apache.org> on 2018/12/21 09:32:22 UTC

[GitHub] oscerd closed pull request #309: Remove the "./" prefix before sanitizing the integration name.

oscerd closed pull request #309: Remove the "./" prefix before sanitizing the integration name.
URL: https://github.com/apache/camel-k/pull/309
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/pkg/util/kubernetes/sanitize.go b/pkg/util/kubernetes/sanitize.go
index e3351a36..4e021707 100644
--- a/pkg/util/kubernetes/sanitize.go
+++ b/pkg/util/kubernetes/sanitize.go
@@ -30,6 +30,7 @@ var disallowedChars = regexp.MustCompile(`[^a-z0-9-]`)
 
 // SanitizeName sanitizes the given name to be compatible with k8s
 func SanitizeName(name string) string {
+	name = strings.TrimPrefix(name, "./")
 	name = strings.Split(name, ".")[0]
 	name = path.Base(name)
 	name = strcase.KebabCase(name)
diff --git a/pkg/util/kubernetes/sanitize_test.go b/pkg/util/kubernetes/sanitize_test.go
new file mode 100644
index 00000000..43078ae8
--- /dev/null
+++ b/pkg/util/kubernetes/sanitize_test.go
@@ -0,0 +1,37 @@
+/*
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You under the Apache License, Version 2.0
+(the "License"); you may not use this file except in compliance with
+the License.  You may obtain a copy of the License at
+
+   http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+package kubernetes
+
+import (
+	"testing"
+)
+
+func TestSanitizeName(t *testing.T) {
+	cases := []map[string]string{
+		{"input": "./abc.java", "expect": "abc"},
+		{"input": "/path/to/abc.js", "expect": "abc"},
+		{"input": "abc.xml", "expect": "abc"},
+		{"input": "./path/to/abc.kts", "expect": "abc"},
+	}
+
+	for _, c := range cases {
+		if name := SanitizeName(c["input"]); name != c["expect"] {
+			t.Errorf("result of %s should be %s, instead of %s", c["input"], c["output"], name)
+		}
+	}
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services