File tree Expand file tree Collapse file tree 2 files changed +21
-1
lines changed
main/java/com/featureprobe/sdk/server/model
test/groovy/com/featureprobe/sdk/server Expand file tree Collapse file tree 2 files changed +21
-1
lines changed Original file line number Diff line number Diff line change 77
88import java .util .*;
99import java .util .regex .Pattern ;
10+ import java .util .regex .PatternSyntaxException ;
1011
1112public final class Condition {
1213
@@ -126,7 +127,12 @@ private boolean matchStringCondition(FPUser user) {
126127 return false ;
127128 }
128129
129- return stringMatcher .match (subjectValue , this .objects );
130+ try {
131+ return stringMatcher .match (subjectValue , this .objects );
132+ } catch (PatternSyntaxException e ) {
133+ logger .error ("Invalid regex pattern" , e );
134+ return false ;
135+ }
130136 }
131137
132138 private boolean matchSegmentCondition (FPUser user , Map <String , Segment > segments ) {
Original file line number Diff line number Diff line change @@ -98,6 +98,20 @@ class ConditionSpec extends Specification {
9898 ! hitMiss
9999 }
100100
101+ def " [matches invalid regex] string condition match" () {
102+ when :
103+ condition. setObjects([" \\\\\\ " ])
104+ user. with(" userId" , " 13797347245" )
105+ condition. setPredicate(PredicateType . MATCHES_REGEX )
106+ def hitMiss = condition. matchObjects(user, segments)
107+ condition. setPredicate(PredicateType . DOES_NOT_MATCH_REGEX )
108+ def hitMiss2 = condition. matchObjects(user, segments)
109+
110+ then :
111+ ! hitMiss
112+ ! hitMiss2
113+ }
114+
101115 def " [is not any of] string condition match" () {
102116 when :
103117 condition. setObjects([" 12345" , " 987654" , " 665544" ])
You can’t perform that action at this time.
0 commit comments