Change first and last character when it doesn't match

This commit is contained in:
Atsushi Ishibashi 2017-10-18 11:10:19 +09:00
parent 210dd08326
commit 3e68f1c505
2 changed files with 16 additions and 2 deletions

View File

@ -34,6 +34,12 @@ func templateCleanImageName(s string) string {
newb[i] = '-'
}
}
if !('a' <= newb[0] && newb[0] <= 'z') {
newb[0] = 'a'
}
if newb[l-1] == '-' {
newb[l-1] = 'a'
}
return string(newb)
}

View File

@ -20,8 +20,16 @@ func Test_templateCleanImageName(t *testing.T) {
expected: "abcde-012345v1-0-0",
},
{
origName: "0123456789012345678901234567890123456789012345678901234567890123456789",
expected: "012345678901234567890123456789012345678901234567890123456789012",
origName: "a123456789012345678901234567890123456789012345678901234567890123456789",
expected: "a12345678901234567890123456789012345678901234567890123456789012",
},
{
origName: "01234567890123456789012345678901234567890123456789012345678901.",
expected: "a1234567890123456789012345678901234567890123456789012345678901a",
},
{
origName: "01234567890123456789012345678901234567890123456789012345678901-",
expected: "a1234567890123456789012345678901234567890123456789012345678901a",
},
}