Skip to content

Commit d8abcd5

Browse files
Zaimwa9claude
andauthored
fix: respect rule type for sub-rules in segment evaluation (#134)
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent f66ebcc commit d8abcd5

3 files changed

Lines changed: 27 additions & 6 deletions

File tree

‎.gitmodules‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
[submodule "tests/Engine/EngineTests/EngineTestData"]
22
path = tests/Engine/EngineTests/EngineTestData
33
url = git@github.com:Flagsmith/engine-test-data.git
4-
branch = v3.5.0
4+
branch = v3.7.0

‎src/Engine/Engine.php‎

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -219,21 +219,42 @@ private static function _contextMatchesRule(
219219
}
220220
}
221221

222-
if ($rule->type === SegmentRuleType::ANY && !$any) {
222+
if ($rule->type === SegmentRuleType::ANY && !$any && !empty($rule->conditions)) {
223223
return false;
224224
}
225225

226+
$anySubRule = false;
226227
foreach ($rule->rules as $subRule) {
227-
$ruleMatches = self::_contextMatchesRule(
228+
$subRuleMatches = self::_contextMatchesRule(
228229
$context,
229230
$subRule,
230231
$segmentKey,
231232
);
232-
if (!$ruleMatches) {
233-
return false;
233+
234+
switch ($rule->type) {
235+
case SegmentRuleType::ALL:
236+
if (!$subRuleMatches) {
237+
return false;
238+
}
239+
break;
240+
case SegmentRuleType::NONE:
241+
if ($subRuleMatches) {
242+
return false;
243+
}
244+
break;
245+
case SegmentRuleType::ANY:
246+
if ($subRuleMatches) {
247+
$anySubRule = true;
248+
break 2;
249+
}
250+
break;
234251
}
235252
}
236253

254+
if ($rule->type === SegmentRuleType::ANY && !$anySubRule && !empty($rule->rules)) {
255+
return false;
256+
}
257+
237258
return true;
238259
}
239260

0 commit comments

Comments
 (0)