@@ -7,8 +7,31 @@ import (
77func validateRecurse (ast Expression , fields FieldConfigurations , maxRawValueLength int ) (int , error ) {
88 switch node := ast .(type ) {
99 case * UnaryExpression :
10- return validateRecurse (node , fields , maxRawValueLength )
10+ switch node .Operator {
11+ case UnaryOpNot :
12+ // this is fine
13+ default :
14+ return 0 , fmt .Errorf ("Invalid unary expression operator: %d" , node .Operator )
15+ }
16+
17+ if node .Operand == nil {
18+ return 0 , fmt .Errorf ("Invalid unary expression operand: nil" )
19+ }
20+ return validateRecurse (node .Operand , fields , maxRawValueLength )
1121 case * BinaryExpression :
22+ switch node .Operator {
23+ case BinaryOpAnd , BinaryOpOr :
24+ // this is fine
25+ default :
26+ return 0 , fmt .Errorf ("Invalid binary expression operator: %d" , node .Operator )
27+ }
28+
29+ if node .Left == nil {
30+ return 0 , fmt .Errorf ("Invalid left hand side of binary expression: nil" )
31+ } else if node .Right == nil {
32+ return 0 , fmt .Errorf ("Invalid right hand side of binary expression: nil" )
33+ }
34+
1235 leftMatches , err := validateRecurse (node .Left , fields , maxRawValueLength )
1336 if err != nil {
1437 return leftMatches , err
@@ -73,6 +96,13 @@ func validateRecurse(ast Expression, fields FieldConfigurations, maxRawValueLeng
7396
7497 node .Value .Converted = coerced
7598 }
99+ } else {
100+ switch node .Operator {
101+ case MatchIsEmpty , MatchIsNotEmpty :
102+ // these don't require values
103+ default :
104+ return 1 , fmt .Errorf ("Match operator %q requires a non-nil value" , node .Operator )
105+ }
76106 }
77107 return 1 , nil
78108 }
0 commit comments