fix: log search is case-sensitive and doesn't escape % / _ (fixes #2) - #3
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
messagefilter usedLIKEinstead ofILIKE, so searches likeerrorwouldn’t matchError: upload failed.Wildcards leaking through user input
%and_were not escaped. That meant:100%matched anything containing100user_idalso matcheduserXidTo fix this:
containsPattern()(internal/adapters/db/like.go)ESCAPE '\'alongside eachILIKEFixes #2
Why
From a user’s perspective,
%and_are just characters — not wildcards. But SQL treats them as wildcards inLIKE/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,
messagebeing 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
containsPatterntested inlike_test.go(no DB required)Integration tests added
log_repo_integration_test.goVerified 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-allpasses (go test ./..., 13 packages)make test-e2enot runThis change only affects query construction (no routes/templates touched), so no UI impact expected. Can run if needed.