Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
0186acc3
Commit
0186acc3
authored
Feb 15, 2015
by
Salvatore Dario Minonne
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extending label.Parse method to support exact match
parent
86434b40
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
0 deletions
+42
-0
selector.go
pkg/labels/selector.go
+0
-0
selector_test.go
pkg/labels/selector_test.go
+0
-0
validation.go
pkg/util/validation.go
+10
-0
validation_test.go
pkg/util/validation_test.go
+32
-0
No files found.
pkg/labels/selector.go
View file @
0186acc3
This diff is collapsed.
Click to expand it.
pkg/labels/selector_test.go
View file @
0186acc3
This diff is collapsed.
Click to expand it.
pkg/util/validation.go
View file @
0186acc3
...
...
@@ -103,3 +103,13 @@ func IsQualifiedName(value string) bool {
}
return
true
}
const
LabelValueFmt
string
=
"([A-Za-z0-9_
\\
-
\\\\
.]*)"
var
labelValueRegexp
=
regexp
.
MustCompile
(
"^"
+
LabelValueFmt
+
"$"
)
const
labelValueMaxLength
int
=
63
func
IsValidLabelValue
(
value
string
)
bool
{
return
(
len
(
value
)
<=
labelValueMaxLength
&&
labelValueRegexp
.
MatchString
(
value
))
}
pkg/util/validation_test.go
View file @
0186acc3
...
...
@@ -189,3 +189,35 @@ func TestIsQualifiedName(t *testing.T) {
}
}
}
func
TestIsValidLabelValue
(
t
*
testing
.
T
)
{
successCases
:=
[]
string
{
"simple"
,
"now-with-dashes"
,
"1-starts-with-num"
,
"end-with-num-1"
,
"-starts-with-dash"
,
"ends-with-dash-"
,
".starts.with.dot"
,
"ends.with.dot."
,
"
\\
preserve
\\
backslash"
,
"1234"
,
// only num
strings
.
Repeat
(
"a"
,
63
),
// to the limit
}
for
i
:=
range
successCases
{
if
!
IsValidLabelValue
(
successCases
[
i
])
{
t
.
Errorf
(
"case[%d] expected success"
,
i
)
}
}
errorCases
:=
[]
string
{
"nospecialchars%^=@"
,
"Tama-nui-te-rā.is.Māori.sun"
,
strings
.
Repeat
(
"a"
,
65
),
}
for
i
:=
range
errorCases
{
if
IsValidLabelValue
(
errorCases
[
i
])
{
t
.
Errorf
(
"case[%d] expected failure"
,
i
)
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment