Skip to content

Commit

Permalink
apply comments
Browse files Browse the repository at this point in the history
  • Loading branch information
gmarek committed Mar 6, 2015
1 parent bb8a4f5 commit 26b7fbe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
11 changes: 6 additions & 5 deletions pkg/util/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ import (
"regexp"
)

const LabelValueFmt string = "[-A-Za-z0-9_.]*"
const kubeChar string = "[A-Za-z0-9]"
const extendedKubeChar string = "[-A-Za-z0-9_.]"
const qualifiedToken string = "(" + kubeChar + extendedKubeChar + "*)?" + kubeChar

const LabelValueFmt string = "((" + kubeChar + extendedKubeChar + "*)?" + kubeChar + ")?"

var labelValueRegexp = regexp.MustCompile("^" + LabelValueFmt + "$")

Expand All @@ -35,10 +39,7 @@ func IsValidAnnotationValue(value string) bool {
return true
}

const kubeToken string = "[A-Za-z0-9]"
const extendedKubeToken string = "[-A-Za-z0-9_.]"
const qualifiedNamePiece string = "(" + kubeToken + extendedKubeToken + "*)?" + kubeToken
const QualifiedNameFmt string = "(" + qualifiedNamePiece + "/)?" + qualifiedNamePiece
const QualifiedNameFmt string = "(" + qualifiedToken + "/)?" + qualifiedToken

var qualifiedNameRegexp = regexp.MustCompile("^" + QualifiedNameFmt + "$")

Expand Down
9 changes: 5 additions & 4 deletions pkg/util/validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,12 +196,9 @@ func TestIsValidLabelValue(t *testing.T) {
"now-with-dashes",
"1-starts-with-num",
"end-with-num-1",
"-starts-with-dash",
"ends-with-dash-",
".starts.with.dot",
"ends.with.dot.",
"1234", // only num
strings.Repeat("a", 63), // to the limit
"", // empty value
}
for i := range successCases {
if !IsValidLabelValue(successCases[i]) {
Expand All @@ -213,6 +210,10 @@ func TestIsValidLabelValue(t *testing.T) {
"nospecialchars%^=@",
"Tama-nui-te-rā.is.Māori.sun",
"\\backslashes\\are\\bad",
"-starts-with-dash",
"ends-with-dash-",
".starts.with.dot",
"ends.with.dot.",
strings.Repeat("a", 64), // over the limit
}
for i := range errorCases {
Expand Down

0 comments on commit 26b7fbe

Please sign in to comment.