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

Commit

Permalink
Merge pull request #5 from launchdarkly/pk/ch1342/regex-standardization
Browse files Browse the repository at this point in the history
made regex matcher return true if the pattern matches anywhere in the…
  • Loading branch information
pkaeding authored Apr 25, 2017
2 parents 996cfbe + 8844964 commit cda5310
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/main/java/com/launchdarkly/client/Operator.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ public boolean apply(JsonPrimitive uValue, JsonPrimitive cValue) {
},
matches {
public boolean apply(JsonPrimitive uValue, JsonPrimitive cValue) {
return uValue.isString() && cValue.isString() && Pattern.matches(cValue.getAsString(), uValue.getAsString());
return uValue.isString() && cValue.isString() &&
Pattern.compile(cValue.getAsString()).matcher(uValue.getAsString()).find();
}
},
contains {
Expand Down
9 changes: 9 additions & 0 deletions src/test/java/com/launchdarkly/client/OperatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,13 @@ public void testNumberComparison() {
assertTrue(Operator.greaterThan.apply(b, a));
assertTrue(Operator.greaterThanOrEqual.apply(b, a));
}

@Test
public void testRegexComparison(){
JsonPrimitive uValue = new JsonPrimitive("hello world");
assertTrue(Operator.matches.apply(uValue, new JsonPrimitive("hello.*rld")));
assertTrue(Operator.matches.apply(uValue, new JsonPrimitive("hello.*orl")));
assertTrue(Operator.matches.apply(uValue, new JsonPrimitive("l+")));
assertTrue(Operator.matches.apply(uValue, new JsonPrimitive("(world|planet)")));
}
}

0 comments on commit cda5310

Please sign in to comment.