Add validation for unbalanced parentheses in rules - #393
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds additional validation to detect unbalanced parentheses in rule expressions during analysis, and extends unit coverage to catch a previously-accepted malformed expression.
Changes:
- Add a post-parse validation in
Analyzer.EnumerateRuleIssues(Rule rule)to flag expressions with unmatched parentheses counts. - Add a unit test case for an expression with an opening parenthesis attached to a token (e.g.,
"(0 AND 1").
Show a summary per file
| File | Description |
|---|---|
| OAT/Analyzer.cs | Adds an end-of-parse check intended to detect unbalanced parentheses in rule expressions. |
| OAT.Tests/ExpressionsTests.cs | Adds a regression test for a rule expression with an unmatched opening parenthesis without a separating space. |
Review details
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
- Files reviewed: 2/2 changed files
- Comments generated: 1
- Review effort level: Lite
Contributor
There was a problem hiding this comment.
Review details
Suppressed comments (2)
OAT/Analyzer.cs:398
- The new unbalanced-parentheses validation only checks total '(' vs ')' counts. This misses expressions where parentheses close before they open but totals still match (e.g.
0) AND (1), which can currently pass validation. Consider also rejecting any expression where the running parentheses balance ever goes negative, while still keeping the end-of-expression count check.
if (foundStarts != foundEnds)
{
yield return new Violation(string.Format(Strings.Get("Err_ClauseUnbalancedParentheses"), expression, rule.Name), rule);
}
OAT.Tests/ExpressionsTests.cs:438
- Tests cover extra opening/closing parentheses, but not the case where the total counts match while the order is invalid (a close before any open), which is an easy regression to miss (e.g.
0) AND (1). Adding a case here will lock in the intended validation behavior.
Assert.False(analyzer.IsRuleValid(invalidRule));
invalidRule = new Rule("UnbalancedOpenParentheses")
{
Expression = "(0 AND 1",
- Files reviewed: 2/2 changed files
- Comments generated: 0 new
- Review effort level: Lite
Chanel (chanel-y)
approved these changes
Aug 13, 2026
Giulia Stocco (gfs)
added a commit
to microsoft/ApplicationInspector
that referenced
this pull request
Aug 16, 2026
The engine's expression validation only reported unbalanced parentheses when closing ones outnumbered opening ones, so a trailing unclosed group passed validation and then threw part way through a scan. That is fixed upstream in microsoft/OAT#393, and the characterization tests now assert the unclosed cases are reported rather than missed. Evaluating an unbalanced expression still throws, so verification remains the gate that keeps a malformed rule away from the analyzer, and the balance check in RulesVerifier is kept: it produces an actionable rule error rather than an engine violation, and it still holds if the package is pinned back. Both projects referencing the package are moved together; AppInspector.Commands also pinned it.
Giulia Stocco (gfs)
added a commit
to microsoft/ApplicationInspector
that referenced
this pull request
Aug 18, 2026
The engine's expression validation only reported unbalanced parentheses when closing ones outnumbered opening ones, so a trailing unclosed group passed validation and then threw part way through a scan. That is fixed upstream in microsoft/OAT#393, and the characterization tests now assert the unclosed cases are reported rather than missed. Evaluating an unbalanced expression still throws, so verification remains the gate that keeps a malformed rule away from the analyzer, and the balance check in RulesVerifier is kept: it produces an actionable rule error rather than an engine violation, and it still holds if the package is pinned back. Both projects referencing the package are moved together; AppInspector.Commands also pinned it.
Giulia Stocco (gfs)
added a commit
to microsoft/ApplicationInspector
that referenced
this pull request
Aug 18, 2026
The engine's expression validation only reported unbalanced parentheses when closing ones outnumbered opening ones, so a trailing unclosed group passed validation and then threw part way through a scan. That is fixed upstream in microsoft/OAT#393, and the characterization tests now assert the unclosed cases are reported rather than missed. Evaluating an unbalanced expression still throws, so verification remains the gate that keeps a malformed rule away from the analyzer, and the balance check in RulesVerifier is kept: it produces an actionable rule error rather than an engine violation, and it still holds if the package is pinned back. Both projects referencing the package are moved together; AppInspector.Commands also pinned it.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.