Skip to content

fix(filter)!: keep operator alias text inside a quoted value - #141

Merged
pdevito3 merged 1 commit into
v2from
fm/qk-breaking-alias-in-value
Oct 3, 2026
Merged

pdevito3 merged 1 commit into
v2from
fm/qk-breaking-alias-in-value

Conversation

@pdevito3

@pdevito3 pdevito3 commented Oct 1, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • ParseFilter no longer runs ReplaceLogicalAliases and ReplaceComparisonAliases on the whole input before the parse. These two methods are removed.
  • The grammar reads the operator aliases. It tries the aliases first, then the canonical operators.
  • On v2, the grammar already resolves query names (fix(filter)!: resolve query names in the grammar again #154). So this PR adds no text rewrite of query names before the parse.

v1.14.2 behavior (and main)

The rewrite before the parse replaces every alias that stands between whitespace with its operator. It does not know about quotes, so it also changes the text inside a quoted value.

New behavior

An alias is an operator only where the grammar expects an operator. A quoted value keeps its text. This includes a value that holds a query name and an alias.

Example

// AndOperator = "and", OrOperator = "or", EqualsOperator = "eq", GreaterThanOperator = "gt"
FilterParser.ParseFilter<Recipe>("""Title eq "salt and pepper or eq gt" and Rating gt 3""", config);
  • v1.14.2 and main: x => ((x.Title == "salt && pepper || == gt") AndAlso (x.Rating > 3)).
  • This PR: x => ((x.Title == "salt and pepper or eq gt") AndAlso (x.Rating > 3)).

Justification

A quoted value is data. The parser must not change it. With the old rewrite, a caller with word aliases (and, or, eq) cannot search for a value that holds one of these words.

Migration

None for most callers. A caller that relied on the rewrite inside a quoted value must write the canonical operator in the value.

README

The Custom Operators section now tells that operator text inside a quoted value does not change.

Tests

  • Unit OperatorAliasTests.alias_text_inside_quoted_value_is_not_replaced
  • Unit OperatorAliasTests.case_insensitive_alias_text_inside_quoted_value_is_not_replaced
  • Unit OperatorAliasTests.can_use_alias_operator_with_query_name
  • Unit OperatorAliasTests.query_name_and_alias_text_inside_quoted_value_is_not_replaced: name eq "name eq x" gives x => (x.Title == "name eq x").
  • Integration FilterParsingRegressionTests.operator_alias_text_inside_quoted_value_is_kept (Postgres)

dotnet test: 565 unit tests and 357 Postgres integration tests (Testcontainers) pass, 0 failures.

Rebase on v2

The branch is rebased on v2. The ReplaceQueryNamesWithPropertyPaths helper and the internal ReplaceAliasesWithPropertyPaths overload from the first version are removed, because v2 resolves query names in the grammar.

@pdevito3
pdevito3 force-pushed the fm/qk-breaking-alias-in-value branch from 1b22df7 to f59a9a2 Compare October 1, 2026 21:37
@pdevito3
pdevito3 changed the base branch from main to v2 October 3, 2026 11:58
The alias rewrite before the parse replaced each alias that stands between whitespace, also inside a quoted value. Title eq "salt and pepper" compared with "salt && pepper". Read the aliases only in the grammar, so a quoted value does not change. The query-name rewrite accepts a comparison alias after the query name.

BREAKING CHANGE: with custom operator aliases, alias text inside a quoted value is no longer replaced with its operator. The filter compares with the value as written.
@pdevito3
pdevito3 force-pushed the fm/qk-breaking-alias-in-value branch from f59a9a2 to 925f508 Compare October 3, 2026 12:03
@pdevito3
pdevito3 merged commit 5b5c87e into v2 Oct 3, 2026
2 checks passed
@pdevito3
pdevito3 deleted the fm/qk-breaking-alias-in-value branch October 3, 2026 12:05
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.

1 participant