Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

Commit cda5310

Browse files
authored
Merge pull request #5 from launchdarkly/pk/ch1342/regex-standardization
made regex matcher return true if the pattern matches anywhere in the…
2 parents 996cfbe + 8844964 commit cda5310

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

src/main/java/com/launchdarkly/client/Operator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ public boolean apply(JsonPrimitive uValue, JsonPrimitive cValue) {
4242
},
4343
matches {
4444
public boolean apply(JsonPrimitive uValue, JsonPrimitive cValue) {
45-
return uValue.isString() && cValue.isString() && Pattern.matches(cValue.getAsString(), uValue.getAsString());
45+
return uValue.isString() && cValue.isString() &&
46+
Pattern.compile(cValue.getAsString()).matcher(uValue.getAsString()).find();
4647
}
4748
},
4849
contains {

src/test/java/com/launchdarkly/client/OperatorTest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,13 @@ public void testNumberComparison() {
2424
assertTrue(Operator.greaterThan.apply(b, a));
2525
assertTrue(Operator.greaterThanOrEqual.apply(b, a));
2626
}
27+
28+
@Test
29+
public void testRegexComparison(){
30+
JsonPrimitive uValue = new JsonPrimitive("hello world");
31+
assertTrue(Operator.matches.apply(uValue, new JsonPrimitive("hello.*rld")));
32+
assertTrue(Operator.matches.apply(uValue, new JsonPrimitive("hello.*orl")));
33+
assertTrue(Operator.matches.apply(uValue, new JsonPrimitive("l+")));
34+
assertTrue(Operator.matches.apply(uValue, new JsonPrimitive("(world|planet)")));
35+
}
2736
}

0 commit comments

Comments
 (0)