Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ private static Boolean contextMatchesCondition(
if (contextValue != null) {
try {
Pattern pattern = Pattern.compile(conditionValue.toString());
return pattern.matcher(contextValue.toString()).find();
return pattern.matcher(contextValue.toString()).lookingAt();
} catch (PatternSyntaxException pse) {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ private static Stream<Arguments> conditionTestData() {
Arguments.of(SegmentConditions.REGEX, "FOO", "[a-z]+", false),
Arguments.of(SegmentConditions.REGEX, 42, "[a-z]+", false),
Arguments.of(SegmentConditions.REGEX, 42, "\\d+", true),
Arguments.of(SegmentConditions.REGEX, "production", "prod", true),
Arguments.of(SegmentConditions.REGEX, "nonproduction", "prod", false),
Arguments.of(SegmentConditions.REGEX, "development", "prod|dev", true),
Arguments.of(SegmentConditions.REGEX, "nondev", "prod|dev", false),
Arguments.of(SegmentConditions.REGEX, "jane@example.com", "@example\\.com$", false),
Arguments.of(SegmentConditions.REGEX, "jane@example.com", "^[^@]+@example\\.com$", true),
Arguments.of(SegmentConditions.REGEX, "jane@example.com.br", "^[^@]+@example\\.com$", false),
Arguments.of(SegmentConditions.REGEX, "Production", "prod", false),
Arguments.of(SegmentConditions.REGEX, "Production", "[Pp]rod", true),
Arguments.of(SegmentConditions.REGEX, "a)(b", "a)(b", false),
Arguments.of(SegmentConditions.MODULO, 2, "2|0", true),
Arguments.of(SegmentConditions.MODULO, 3, "2|0", false),
Arguments.of(SegmentConditions.MODULO, 2.0, "2|0", true),
Expand Down Expand Up @@ -113,7 +123,7 @@ public void testSegmentConditionMatchesTraitValue(
Object traitValue,
Object conditionValue,
Boolean expectedResponse) {

// Given
final EvaluationContext context = EngineMappers.mapContextAndIdentityDataToContext(
FlagsmithTestHelper.evaluationContext(), "foo",
Collections.singletonMap("foo", traitValue));
Expand All @@ -125,8 +135,10 @@ public void testSegmentConditionMatchesTraitValue(
.withOperator(condition).withProperty("foo")
.withValue(conditionValue)))));

// When
Boolean actualResult = SegmentEvaluator.isContextInSegment(context, segmentContext);

// Then
assertEquals(expectedResponse, actualResult);
}

Expand Down
Loading