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 "tests/Engine/EngineTests/EngineTestData"]
path = tests/Engine/EngineTests/EngineTestData
url = git@github.com:Flagsmith/engine-test-data.git
tag = v3.4.1
tag = v3.5.0
22 changes: 12 additions & 10 deletions src/Engine/Engine.php
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,15 @@ private static function _contextMatchesCondition(
$condition,
$segmentKey,
): bool {
$contextValue = self::_getContextValue($context, $condition->property);
// NOTE: 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.
if ($condition->operator === SegmentConditionOperator::PERCENTAGE_SPLIT && empty($condition->property)) {
$contextValue = $context->identity?->key;
} else {
$contextValue = self::_getContextValue($context, $condition->property);
}

$cast = self::_getCaster($contextValue);

switch ($condition->operator) {
Expand Down Expand Up @@ -282,22 +290,16 @@ private static function _contextMatchesCondition(
return in_array($contextValue, $inValues, strict: true);

case SegmentConditionOperator::PERCENTAGE_SPLIT:
if (!is_numeric($condition->value)) {
if ($contextValue === null) {
return false;
}

/** @var array<string> $objectIds */
if ($contextValue !== null) {
$objectIds = [$segmentKey, $contextValue];
} elseif ($context->identity !== null) {
$objectIds = [$segmentKey, $context->identity->key];
} else {
if (!is_numeric($condition->value)) {
return false;
}

$hashing = new Hashing();
$threshold = $hashing->getHashedPercentageForObjectIds(
$objectIds,
[$segmentKey, $contextValue],
);
return $threshold <= ((float) $condition->value);

Expand Down