Skip to content

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

Open
pdevito3 wants to merge 1 commit into
mainfrom
fm/qk-breaking-alias-in-value
Open

pdevito3 wants to merge 1 commit into
mainfrom
fm/qk-breaking-alias-in-value

Conversation

@pdevito3

@pdevito3 pdevito3 commented Oct 1, 2026 •

Copy link
Copy Markdown
Owner

For later consideration in a major version. Do not merge now. #134 restored the v1.14.2 alias rewrite to keep v1.x compatible (restore commit f5209e5). This PR re-applies 39312a1. The captain decides on this PR separately.

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.
  • The query-name rewrite before the parse also matches a query name in front of a comparison alias (name eq "x"), because the aliases are not replaced yet when it runs.

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.

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

These tests come back from main before #134:

  • Unit OperatorAliasTests.alias_text_inside_quoted_value_is_replaced -> alias_text_inside_quoted_value_is_not_replaced
  • Unit OperatorAliasTests.case_insensitive_alias_text_inside_quoted_value_is_replaced -> case_insensitive_alias_text_inside_quoted_value_is_not_replaced
  • Unit OperatorAliasTests.can_use_alias_operator_with_query_name_and_alias_text_in_the_value_is_replaced -> can_use_alias_operator_with_query_name
  • Integration FilterParsingRegressionTests.operator_alias_text_inside_quoted_value_is_replaced -> operator_alias_text_inside_quoted_value_is_kept (Postgres)

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

Rebase on main

This branch is rebased on current main. Main checks only the input length before the parse, and counts the nesting depth in the grammar. So ParseFilter keeps EnsureWithinInputLength and then calls ReplaceQueryNamesWithPropertyPaths.

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 1b22df7 to f59a9a2 Compare October 1, 2026 21:37
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