Skip to content

Don't merge raw and quoted arguments when grouping functions - #468

Merged
mbrt merged 1 commit into
masterfrom
bug/raw-grouping
Sep 26, 2026
Merged

mbrt merged 1 commit into
masterfrom
bug/raw-grouping

Conversation

@mbrt

@mbrt mbrt commented Sep 26, 2026

Copy link
Copy Markdown
Owner

The simplifier merges leaves using the same function under the same operator, e.g. or(from:a, from:b) becomes from:{a b}. When any of the merged leaves was raw (isEscaped: true, or a downloaded filter), the whole merged leaf was marked raw. Since quoting is skipped for all the arguments of a raw leaf, the non-raw ones silently lost their quotes:

or: [
  { from: 'John Smith' },
  { from: '-(foo bar)', isEscaped: true },
]

produced from:{John Smith -(foo bar)}, which matches mail from "John" or "Smith" instead of "John Smith".

Group raw and non-raw leaves separately instead, which now produces {from:"John Smith" from:-(foo bar)}. When the or is at the top of a rule it is split into one Gmail filter per leaf, as already happens for different functions (e.g. or(from:a, to:b)). Leaves that are all raw, or all non-raw, are grouped exactly as before.

A function can now produce two sibling leaves that differ only in the raw flag. They come out of a map, in random order, and the tree sort didn't tell them apart, so the order of the generated query (and with it the diff against Gmail) would change between runs. Sort non-raw leaves before raw ones to keep the output deterministic.

The simplifier merges leaves using the same function under the same
operator, e.g. or(from:a, from:b) becomes from:{a b}. When any of the
merged leaves was raw (`isEscaped: true`, or a downloaded filter), the
whole merged leaf was marked raw. Since quoting is skipped for all the
arguments of a raw leaf, the non-raw ones silently lost their quotes:

    or: [
      { from: 'John Smith' },
      { from: '-(foo bar)', isEscaped: true },
    ]

produced `from:{John Smith -(foo bar)}`, which matches mail from "John"
or "Smith" instead of "John Smith".

Group raw and non-raw leaves separately instead, which now produces
`{from:"John Smith" from:-(foo bar)}`. When the `or` is at the top of a
rule it is split into one Gmail filter per leaf, as already happens for
different functions (e.g. or(from:a, to:b)). Leaves that are all raw,
or all non-raw, are grouped exactly as before.

A function can now produce two sibling leaves that differ only in the
raw flag. They come out of a map, in random order, and the tree sort
didn't tell them apart, so the order of the generated query (and with
it the diff against Gmail) would change between runs. Sort non-raw
leaves before raw ones to keep the output deterministic.
@mbrt mbrt added the kind/bug Something isn't working label Sep 26, 2026
@codecov

codecov Bot commented Sep 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 41.86%. Comparing base (f51825d) to head (2a6434d).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #468      +/-   ##
==========================================
+ Coverage   41.37%   41.86%   +0.48%     
==========================================
  Files          54       54              
  Lines        3693     3698       +5     
==========================================
+ Hits         1528     1548      +20     
+ Misses       2063     2049      -14     
+ Partials      102      101       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mbrt
mbrt merged commit 87e72a5 into master Sep 26, 2026
5 checks passed
@mbrt
mbrt deleted the bug/raw-grouping branch September 26, 2026 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant