1
0
Fork 0
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:
Denis Belyshev 2019-05-28 13:13:57 +03:00
parent 22b942d229
commit b42f517093
2 changed files with 17 additions and 1 deletions

View file

@ -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) {

View file

@ -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)
}