XUtils: ignore empty needles in a multi-term filter - #2102
Conversation
`String_contains_i()` splits the filter on `|` and passes each needle to
`strcasestr()`, which reports a match against anything for an empty needle.
`String_split()` emits an empty field for a leading or repeated separator but
drops a trailing one, so the filter behaved inconsistently:
filter matches
nginx| nothing extra (trailing separator is dropped)
|nginx every row
nginx||postgres every row
Typing or pasting a stray `|` therefore stopped the filter from filtering,
while the same mistake at the end of the line was harmless. Empty needles are
now skipped, so the two spellings agree.
A filter of only separators carries no search term and still matches
everything, as an empty filter does.
Verified on darwin against the built `XUtils.o`, over 14 cases covering a
leading, trailing, doubled and interior separator on both the matching and
non-matching side; reverting this change fails exactly the `|nginx` and
`nginx||postgres` cases. No new warnings under the tree's own flags.
Assisted-by: Claude Code (Claude Opus 5)
Signed-off-by: Roshan Ramani <roshanramani.dev@gmail.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Team Run ID: 📒 Files selected for processing (1)
Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review. 📝 WalkthroughWalkthrough
Poem
Merge Risk: ⚪ Minimal · up to Filters with leading, repeated, or separator-only terms now behave as intended without changing non-empty term matching. The change is ready to merge. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
I'll merge this without the first AI comment. Today's AIs tend to work around their limited memory and context window by adding rather useless, verbose (to a human) commentary. So I'll cull that one. Otherwise thank you for the PR. |
|
Merged as b9a2a63 |
String_contains_i()splits the filter on|and hands each needle tostrcasestr(), which reports a match against anything for an empty needle.String_split()emits an empty field for a leading or repeated separator but drops a trailing one, so the same typo behaved differently depending on where it landed:nginx||nginxnginxrowsnginx||postgresnginxorpostgresrowsSo while composing a multi-term filter, a stray or half-typed
|silently stopped the filter from filtering — and the same mistake at the end of the line was harmless. That inconsistency is what convinced me it wasn't intentional: if an empty alternative were meant to match everything, a trailing|would do it too.Empty needles are now skipped. A filter consisting only of separators carries no search term and still matches everything, the same as an empty filter — the incremental-search callers already treat a null filter that way.
Fixed in
String_contains_i()rather thanString_split(), since the empty-field behaviour there is relied on elsewhere and only the filter's semantics are wrong.Verification, on darwin: linked a small driver against the tree's own
XUtils.oand ran 14 cases covering a leading, trailing, doubled and interior separator on both the matching and non-matching side, plus case-insensitivity and separators alone. All pass; reverting the change fails exactly|nginxandnginx||postgres. Fullmakeclean with no new warnings under the tree's flags (-Wall -Wextra -pedanticand the rest).I could not add a regression test: the only harness here is
test_spec.lua, which drives a terminal rather than calling into C, so there is nowhere for a unit test of this to live. Happy to write atest_spec.luacase that types a filter into a live htop if you would rather have coverage that way — it seemed worse than the C-level evidence above, but it is your call.AI disclosure per
docs/ai-contributions-policy.md: found and written with Claude Code (Claude Opus 5), recorded in the commit'sAssisted-by:trailer. @rawsun007 authorised theSigned-off-by:and reviewed the change.