Skip to content

fix: log search is case-sensitive and doesn't escape % / _ (fixes #2) - #3

Merged
t0uh33d merged 1 commit into
mainfrom
fix/log-search-matching
Aug 13, 2026
Merged

fix: log search is case-sensitive and doesn't escape % / _ (fixes #2)#3
t0uh33d merged 1 commit into
mainfrom
fix/log-search-matching

Conversation

@huzaif-fahad

Copy link
Copy Markdown
Contributor

What this changes

This PR fixes how we build “contains” filters across log search (device, OS, message, URL, project name).

There were two subtle issues that didn’t throw errors but returned incorrect results:

  • Case sensitivity mismatch
    The free-text message filter used LIKE instead of ILIKE, so searches like error wouldn’t match Error: upload failed.

  • Wildcards leaking through user input
    % and _ were not escaped. That meant:

    • 100% matched anything containing 100
    • user_id also matched userXid

To fix this:

  • Introduced a shared helper containsPattern() (internal/adapters/db/like.go)
  • Updated all six call sites to use it
  • Explicitly added ESCAPE '\' alongside each ILIKE

Fixes #2


Why

From a user’s perspective, % and _ are just characters — not wildcards. But SQL treats them as wildcards in LIKE/ILIKE, which caused surprising matches.

Interestingly, the Flutter SDK’s local DB layer already escapes these correctly. This change aligns the server behavior with that expectation instead of fixing it in only one place.

Also, message being case-sensitive while other filters (device_model, os_name, url) were not looks unintentional -this makes behavior consistent across all fields.

Adding ESCAPE '\' doesn’t change behavior (Postgres already defaults to it), but it makes the intent explicit and avoids relying on implicit settings.


Tests

  • Unit tests added

    • containsPattern tested in like_test.go (no DB required)
  • Integration tests added

    • Covers all cases from the issue in log_repo_integration_test.go
  • Verified failure before fix
    Reverted changes and ran against Postgres 16:

    • error → expected match, got []
    • % → treated as wildcard, matched unintended rows
    • \_ → matched unintended patterns
      FAIL

    Reapplied fix:
    PASS

  • make test-all passes (go test ./..., 13 packages)

  • make test-e2e not run
    This change only affects query construction (no routes/templates touched), so no UI impact expected. Can run if needed.

@huzaif-fahad huzaif-fahad changed the title fixes #2 fix: log search is case-sensitive and doesn't escape % / _ (fixes #2) Aug 12, 2026
@huzaif-fahad
huzaif-fahad requested a review from t0uh33d August 12, 2026 14:12
@huzaif-fahad huzaif-fahad added bug Something isn't working good first issue Good for newcomers labels Aug 12, 2026
@t0uh33d
t0uh33d merged commit ab128e4 into main Aug 13, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working good first issue Good for newcomers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Log search returns wrong results: message filter is case-sensitive, and '% / _' are treated as wildcards

2 participants