Skip to content
Merged
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
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[submodule "src/test/java/com/flagsmith/flagengine/enginetestdata"]
path = src/test/java/com/flagsmith/flagengine/enginetestdata
url = git@github.com:Flagsmith/engine-test-data.git
tag = v3.4.1
tag = v3.5.0
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.flagsmith.flagengine.EvaluationContext;
import com.flagsmith.flagengine.IdentityContext;
import com.flagsmith.flagengine.SegmentCondition;
import com.flagsmith.flagengine.SegmentContext;
import com.flagsmith.flagengine.SegmentRule;
Expand All @@ -21,6 +22,7 @@
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
import java.util.stream.Collectors;
import org.apache.commons.lang3.StringUtils;

public class SegmentEvaluator {
private static ObjectMapper mapper = new ObjectMapper();
Expand Down Expand Up @@ -77,10 +79,25 @@ private static Boolean contextMatchesCondition(
EvaluationContext context,
SegmentCondition condition,
String segmentKey) {
Object contextValue = getContextValue(context, condition.getProperty());
Object contextValue = null;
Object conditionValue = condition.getValue();
String conditionProperty = condition.getProperty();
SegmentConditions operator = condition.getOperator();

if (operator == SegmentConditions.PERCENTAGE_SPLIT && StringUtils.isEmpty(conditionProperty)) {
// Currently, the only supported condition with a blank property
// is percentage split.
// In this case, we use the identity key as context value.
// This is mainly to support legacy segments created before
// we introduced JSONPath support.
IdentityContext identity = context.getIdentity();
if (!(identity == null)) {
contextValue = identity.getKey();
}
} else {
contextValue = getContextValue(context, conditionProperty);
}

switch (operator) {
case IN:
if (contextValue == null || contextValue instanceof Boolean) {
Expand Down Expand Up @@ -109,20 +126,14 @@ private static Boolean contextMatchesCondition(
return conditionList.contains(String.valueOf(contextValue));

case PERCENTAGE_SPLIT:
String key;
if (contextValue == null) {
if (context.getIdentity() == null) {
return false;
}
key = context.getIdentity().getKey();
} else {
key = contextValue.toString();
return false;
}
List<String> objectIds = List.of(segmentKey, key);
List<String> objectIds = List.of(segmentKey, contextValue.toString());

final float floatValue;
try {
floatValue = Float.parseFloat(String.valueOf(condition.getValue()));
floatValue = Float.parseFloat(String.valueOf(conditionValue));
} catch (NumberFormatException e) {
return false;
}
Expand Down