Skip to content

Evaluate and before or in the filter DSL - #242

Open
soujasK wants to merge 1 commit into
honeynet:mainfrom
soujasK:fix/and-or-precedence
Open

soujasK wants to merge 1 commit into
honeynet:mainfrom
soujasK:fix/and-or-precedence

Conversation

@soujasK

@soujasK soujasK commented Nov 10, 2026

Copy link
Copy Markdown

Fixes #241

What changed

filterEvent walked the right-nested query tree as it was parsed, so A and B or C was evaluated as A and (B or C). It now flattens the chain into clauses and operators and evaluates it as an or of and groups, so and binds tighter than or, as in Wireshark display filters:

  • not still applies to the clause right after it.
  • Parenthesized groups are still evaluated on their own.
  • Evaluation still short-circuits: once an and group fails, its remaining clauses are skipped, and the first group that matches returns.

The grammar is unchanged, so the generated types, the syntax diagram and the suggestions are untouched. frontend/syntax.md gets a short "Precedence" section.

Testing

  • New and binds tighter than or tests in frontend/__tests__/dsl.test.ts: A and B or C, the same query with the sides of or swapped, A or B and C or D, not inside a chain, and parentheses grouping an or first. Two of them (A and B or C, A or B and C or D) fail on main; all pass with this change.
  • npm run test: 69 passed. Prettier is clean on the changed files. npm run check reports only the existing missing .routify/routes.default.js (generated by a build), not from this change.

Note: this changes the result of saved queries that mix and and or without parentheses. That's the point of the fix, but I'm happy to adjust if you'd prefer a different approach.

AI disclosure: I used Claude Code to help find the bug, write the fix and tests, and draft this description. I reviewed the change and ran the tests myself.

The grammar nests a chain to the right, and filterEvent evaluated it that
way, so "A and B or C" was read as "A and (B or C)". Flatten the chain and
evaluate it as an or of and groups, so it is "(A and B) or C" as in
Wireshark display filters. not still applies to the clause after it, and
parentheses still group explicitly.
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.

Filter reads A and B or C as A and (B or C)

1 participant