mirror of https://github.com/databricks/cli.git
Fixed job name normalisation for bundle generate (#1601)
## Changes Fixes #1537 ## Tests Added unit test
This commit is contained in:
parent
e1474a38f9
commit
6d710a411a
|
@ -22,7 +22,7 @@ func TestGetShortUserName(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
email: "test$.user@example.com",
|
email: "test$.user@example.com",
|
||||||
expected: "test__user",
|
expected: "test_user",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
email: `jöhn.dœ@domain.com`, // Using non-ASCII characters.
|
email: `jöhn.dœ@domain.com`, // Using non-ASCII characters.
|
||||||
|
@ -38,7 +38,7 @@ func TestGetShortUserName(t *testing.T) {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
email: `"_quoted"@domain.com`, // Quoted strings can be part of the local-part.
|
email: `"_quoted"@domain.com`, // Quoted strings can be part of the local-part.
|
||||||
expected: "__quoted_",
|
expected: "quoted",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
email: `name-o'mally@website.org`, // Single quote in the local-part.
|
email: `name-o'mally@website.org`, // Single quote in the local-part.
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package textutil
|
package textutil
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"unicode"
|
"unicode"
|
||||||
)
|
)
|
||||||
|
@ -9,7 +10,14 @@ import (
|
||||||
// including spaces and dots, which are not supported in e.g. experiment names or YAML keys.
|
// including spaces and dots, which are not supported in e.g. experiment names or YAML keys.
|
||||||
func NormalizeString(name string) string {
|
func NormalizeString(name string) string {
|
||||||
name = strings.ToLower(name)
|
name = strings.ToLower(name)
|
||||||
return strings.Map(replaceNonAlphanumeric, name)
|
s := strings.Map(replaceNonAlphanumeric, name)
|
||||||
|
|
||||||
|
// replacing multiple underscores with a single one
|
||||||
|
re := regexp.MustCompile(`_+`)
|
||||||
|
s = re.ReplaceAllString(s, "_")
|
||||||
|
|
||||||
|
// removing leading and trailing underscores
|
||||||
|
return strings.Trim(s, "_")
|
||||||
}
|
}
|
||||||
|
|
||||||
func replaceNonAlphanumeric(r rune) rune {
|
func replaceNonAlphanumeric(r rune) rune {
|
||||||
|
|
|
@ -46,6 +46,10 @@ func TestNormalizeString(t *testing.T) {
|
||||||
{
|
{
|
||||||
input: "TestTestTest",
|
input: "TestTestTest",
|
||||||
expected: "testtesttest",
|
expected: "testtesttest",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
input: ".test//test..test",
|
||||||
|
expected: "test_test_test",
|
||||||
}}
|
}}
|
||||||
|
|
||||||
for _, c := range cases {
|
for _, c := range cases {
|
||||||
|
|
Loading…
Reference in New Issue