mirror of
https://github.com/kyverno/kyverno.git
synced 2025-03-31 03:45:17 +00:00
Fixed crash when checking operator on strings lesser than 2 chars
This commit is contained in:
parent
22b942d229
commit
b42f517093
2 changed files with 17 additions and 1 deletions
|
@ -240,6 +240,10 @@ func validateNumber(value, pattern interface{}, operator Operator) bool {
|
|||
}
|
||||
|
||||
func getOperatorFromStringPattern(pattern string) Operator {
|
||||
if len(pattern) < 2 {
|
||||
return Equal
|
||||
}
|
||||
|
||||
if pattern[:len(MoreEqual)] == string(MoreEqual) {
|
||||
return MoreEqual
|
||||
}
|
||||
|
@ -260,7 +264,7 @@ func getOperatorFromStringPattern(pattern string) Operator {
|
|||
return NotEqual
|
||||
}
|
||||
|
||||
return ""
|
||||
return Equal
|
||||
}
|
||||
|
||||
func getNumberAndStringPartsFromPattern(pattern string) (number, str string) {
|
||||
|
|
|
@ -269,3 +269,15 @@ func TestValidateNumberWithStr_MoreAndWildCard(t *testing.T) {
|
|||
func TestValidateNumberWithStr_NoStr(t *testing.T) {
|
||||
assert.Assert(t, validateNumberWithStr(2048, "1024", "", More))
|
||||
}
|
||||
|
||||
func TestGetOperatorFromStringPattern_OneChar(t *testing.T) {
|
||||
assert.Equal(t, getOperatorFromStringPattern("f"), Equal)
|
||||
}
|
||||
|
||||
func TestGetOperatorFromStringPattern_EmptyString(t *testing.T) {
|
||||
assert.Equal(t, getOperatorFromStringPattern(""), Equal)
|
||||
}
|
||||
|
||||
func TestGetOperatorFromStringPattern_OnlyOperator(t *testing.T) {
|
||||
assert.Equal(t, getOperatorFromStringPattern(">="), MoreEqual)
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue