Skip to content

Parse nested rule Operator case-insensitively in RuleCompiler to match RuleValidator - #759

Merged
YogeshPraj merged 1 commit into
microsoft:mainfrom
MBrekhof:fix/nested-operator-case-insensitive
Nov 3, 2026
Merged

YogeshPraj merged 1 commit into
microsoft:mainfrom
MBrekhof:fix/nested-operator-case-insensitive

Conversation

@MBrekhof

Copy link
Copy Markdown
Contributor

Problem

RuleValidator validates rule.Operator using Enum.TryParse<ExpressionType>(op, true, out _) (case-insensitive, allowing "and", "or", "andalso", "orelse"), whereas RuleCompiler.GetDelegateForRule calls Enum.TryParse(rule.Operator, out ExpressionType nestedOperator) without ignoreCase: true.

As a result, a nested rule with "Operator": "and" or "Operator": "or" passes validation without errors, fails Enum.TryParse during compilation, and falls into the default InvalidOperationException($"{rule.Operator} is not supported") branch.

Solution

  • Pass ignoreCase: true to Enum.TryParse(rule.Operator, true, out ExpressionType nestedOperator) in RuleCompiler.GetDelegateForRule.
  • Added unit tests in test/RulesEngine.UnitTest/NestedOperatorCaseInsensitiveTest.cs verifying lowercase "and" and "or" operators on nested rules.

@YogeshPraj
YogeshPraj enabled auto-merge (squash) November 3, 2026 10:45
@YogeshPraj
YogeshPraj merged commit 682b806 into microsoft:main Nov 3, 2026
3 checks passed
YogeshPraj added a commit that referenced this pull request Nov 4, 2026
#759 re-saved RuleCompiler.cs without its UTF-8 BOM. Restore it so the
file matches its original encoding; no other change.

Co-authored-by: MBrekhof <martin.brekhof@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: YogeshPraj <yoprajap@microsoft.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants