From 3e51cd0bb9ddceaf93e27ff66e6c306e22ed7d28 Mon Sep 17 00:00:00 2001 From: wadii Date: Thu, 7 May 2026 10:18:20 +0200 Subject: [PATCH] fix: respect rule type for sub-rules in segment evaluation Sub-rules were always evaluated with ALL logic, ignoring the parent rule's type field (ANY/ALL/NONE). Now uses type-aware matching for sub-rules, matching the existing conditions behavior. Bumps engine-test-data from v3.5.0 to v3.7.0 which includes test cases for this fix. Equivalent fix to flagsmith-engine#313. Co-Authored-By: Claude Opus 4.7 (1M context) --- .gitmodules | 2 +- Flagsmith.Engine/Engine.cs | 24 +++++++++++++++++++++++- Flagsmith.EngineTest/EngineTestData | 2 +- 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/.gitmodules b/.gitmodules index 4897e31..737b0aa 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ [submodule "Flagsmith.EngineTest/EngineTestData"] path = Flagsmith.EngineTest/EngineTestData url = git@github.com:Flagsmith/engine-test-data.git - branch = v3.5.0 + branch = v3.7.0 diff --git a/Flagsmith.Engine/Engine.cs b/Flagsmith.Engine/Engine.cs index 4cabe8d..f2567bb 100644 --- a/Flagsmith.Engine/Engine.cs +++ b/Flagsmith.Engine/Engine.cs @@ -168,7 +168,29 @@ private static bool ContextMatchesRule<_, __>(EvaluationContext<_, __> context, break; } - return matchesConditions && (rule.Rules?.All(r => ContextMatchesRule(context, r, segmentKey)) ?? true); + if (!matchesConditions) + return false; + + if (rule.Rules is null || !rule.Rules.Any()) + return true; + + bool matchesSubRules; + switch (rule.Type) + { + case TypeEnum.All: + matchesSubRules = rule.Rules.All(r => ContextMatchesRule(context, r, segmentKey)); + break; + case TypeEnum.Any: + matchesSubRules = rule.Rules.Any(r => ContextMatchesRule(context, r, segmentKey)); + break; + case TypeEnum.None: + matchesSubRules = !rule.Rules.Any(r => ContextMatchesRule(context, r, segmentKey)); + break; + default: + matchesSubRules = false; + break; + } + return matchesSubRules; } private static bool ContextMatchesCondition<_, __>(EvaluationContext<_, __> context, Condition condition, string segmentKey) diff --git a/Flagsmith.EngineTest/EngineTestData b/Flagsmith.EngineTest/EngineTestData index 7840a13..4b29dc7 160000 --- a/Flagsmith.EngineTest/EngineTestData +++ b/Flagsmith.EngineTest/EngineTestData @@ -1 +1 @@ -Subproject commit 7840a1349b601df3b6b4a089f40864f659801afb +Subproject commit 4b29dc772a764364af2dd504ecefbdf74cf5473f