Repository navigation
Conversation
…xed name
parseUserID used strings.Contains(q, "user:me") to detect the current-user
filter, so any username starting with "me" was truncated to "me": the search
returned the login user's posts instead of the named author's, and the rest of
the name ("lissa" for "melissa") was searched as a keyword.
Match the whole name after "user:" instead, so only an exact "user:me" resolves
to the current login user and every other name goes through the username
lookup.
Adds regression coverage for exact "user:me", me-prefixed usernames, unknown
names and queries without a user filter.
Author
|
Closing this: PR #1666 by @PDGGK already fixed this on the |
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.
Fixes #1665
Proposed Changes
parseUserIDmatched the current-user filter withstrings.Contains(q, "user:me"), so any username starting withmewas treated asuser:me: the search returned the login user's posts instead of the named author's, and the remainder of the name (lissaformelissa) was left in the query and searched as a keyword.user:withme. Only an exactuser:meresolves to the current login user; every other name goes through the existing username lookup.internal/service/search_parser/search_parser_test.gowith regression coverage for exactuser:me, me-prefixed usernames (melissa,megan), me-prefixed usernames with keywords, unknown names, ordinary usernames, and queries without a user filter.Why this shape
The bug is a prefix collision, not a missing feature: the intended behaviour ("
user:memeans the current user") was already there, but the substring test also claimeduser:melissa. Comparing the captured name keeps the existing contract and leaves every other filter ([tag],score:,is:question, …) untouched.Verification
All commands run on branch
fix/search-user-me-prefixat commit5e68e73, macOS arm64, Go 1.27.3, module Go directive 1.25.0.New regression tests:
Mutation check — reverting only the product change and re-running the same tests makes them fail, so they really pin the bug:
Whole test suite, no regressions (25 packages,
internal/...+pkg/...):Build, format, lint and ASF header:
I did not run
make test(the repository integration suite ininternal/repo/repo_test), because it needs Docker to bring up MySQL/PostgreSQL and the behaviour I touched is pure query parsing with no database access. The new tests are unit tests in the package, not integration tests.Risk
Low. The change only affects how the
user:filter token is recognised. A search containinguser:mebehaves exactly as before; a search for a real username that starts withmenow finds that author, which is the reported expectation.