Skip to content

fix: search user:me only matches the current user, not every me-prefixed name - #1687

Closed
Goldloli wants to merge 1 commit into
apache:mainfrom
Goldloli:fix/search-user-me-prefix
Closed

Goldloli wants to merge 1 commit into
apache:mainfrom
Goldloli:fix/search-user-me-prefix

Conversation

@Goldloli

Copy link
Copy Markdown

Fixes #1665

Proposed Changes

  • parseUserID matched the current-user filter with strings.Contains(q, "user:me"), so any username starting with me was treated as user:me: the search returned the login user's posts instead of the named author's, and the remainder of the name (lissa for melissa) was left in the query and searched as a keyword.
  • The check now compares the whole name captured after user: with me. Only an exact user:me resolves to the current login user; every other name goes through the existing username lookup.
  • Adds internal/service/search_parser/search_parser_test.go with regression coverage for exact user: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:me means the current user") was already there, but the substring test also claimed user: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-prefix at commit 5e68e73, macOS arm64, Go 1.27.3, module Go directive 1.25.0.

  1. New regression tests:

    go test ./internal/service/search_parser/ -run TestSearchParser -v
    --- PASS: TestSearchParserParseUserID (8 subtests)
    --- PASS: TestSearchParserParseStructureResolvesMePrefixedUsername
    ok  github.com/apache/answer/internal/service/search_parser
    
  2. Mutation check — reverting only the product change and re-running the same tests makes them fail, so they really pin the bug:

    --- FAIL: TestSearchParserParseStructureResolvesMePrefixedUsername
        expected: "melissa-id"
        actual  : "current-login-user-id"
        Should be empty, but was [lissa]
    
  3. Whole test suite, no regressions (25 packages, internal/... + pkg/...):

    go test ./internal/... ./pkg/...   # 25 ok, 0 FAIL
    
  4. Build, format, lint and ASF header:

    go build ./...                                  # exit 0
    gofmt -l internal/service/search_parser/        # empty
    go vet ./internal/service/search_parser/        # clean
    golangci-lint run ./internal/service/search_parser/...   # 0 issues
    bash ./script/check-asf-header.sh               # All files have proper header
    

I did not run make test (the repository integration suite in internal/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 containing user:me behaves exactly as before; a search for a real username that starts with me now finds that author, which is the reported expectation.

…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.
@Goldloli

Copy link
Copy Markdown
Author

Closing this: PR #1666 by @PDGGK already fixed this on the dev branch (merged 2026-11-11), with the same approach — the user: token is compared against me instead of using a substring check. I opened this without checking dev, which is where the project's development work lands; my preflight only compared against main, so the duplicate slipped through. Sorry for the noise.

@Goldloli Goldloli closed this Nov 27, 2026
@Goldloli
Goldloli deleted the fix/search-user-me-prefix branch November 27, 2026 13:23
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.

Searching user:<username> returns the wrong posts when the username starts with "me"

1 participant