Skip to content

fix(search): prevent username prefix me from matching user:me (#1665) - #1667

Closed
granbellllc-png wants to merge 1 commit into
apache:mainfrom
granbellllc-png:fix/issue-1665-search-user-me-prefix
Closed

granbellllc-png wants to merge 1 commit into
apache:mainfrom
granbellllc-png:fix/issue-1665-search-user-me-prefix

Conversation

@granbellllc-png

Copy link
Copy Markdown

Fixes #1665.

Motivation

When searching user:<username> where the username begins with me (such as user:melissa), the parser previously executed strings.Contains(q, "user:me") before checking the username regex. This caused user:melissa to be matched as user:me, replacing user:me with empty string and leaving lissa to be searched as a separate word query.

Fix

  • In parseUserID, extract the full username token via user:(\S+) first.
  • Check if the extracted username is exactly "me" to assign currentUserID.
  • Otherwise, query GetUserBasicInfoByUserName for the exact username.
  • Added comprehensive unit tests in internal/service/search_parser/search_parser_test.go.

…he#1665)

- In parseUserID, extract username from user:(\S+) before checking for 'me'
- Only treat query as current user search if exact username token is 'me'
- Add unit tests for parseUserID with user:me and usernames prefixed with me

Fixes apache#1665
@LinkinStars

Copy link
Copy Markdown
Member

Thanks for the contribution! This issue has already been fixed in #1666, which is merged into dev, so this PR duplicates that fix.

@granbellllc-png

Copy link
Copy Markdown
Author

Thank you @LinkinStars for the review and update! Understood that #1666 already addressed this in dev. Closing this PR accordingly.

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"

2 participants