Skip to content

fix: tag search never matches on slug name - #1563

Open
ngineer420 wants to merge 1 commit into
apache:mainfrom
ngineer420:fix/tag-search-case-insensitive
Open

fix: tag search never matches on slug name#1563
ngineer420 wants to merge 1 commit into
apache:mainfrom
ngineer420:fix/tag-search-case-insensitive

Conversation

@ngineer420

Copy link
Copy Markdown

Proposed Changes

Tag search never matches on slug_name.

In tagCommonRepo.GetTagPage, the search term is formatted into LOWER(%s) and
passed as the value of the LIKE, so the function name ends up inside the
pattern rather than being applied to the column:

builder.Like{"slug_name", fmt.Sprintf("LOWER(%s)", tag.SlugName)}
// -> slug_name LIKE '%LOWER(coco)%'

That can never match. Only the display_name clause does any work, and LIKE
is case-sensitive on PostgreSQL, so searching for a tag by the name it is
written in returns nothing:

GET /answer/api/v1/tags/page?slug_name=Coco   ->  ["coco"]
GET /answer/api/v1/tags/page?slug_name=coco   ->  []

Tags are lower case by convention, so lower case is what people type, and the
tag filter appears to report that no such tag exists.

  • Lower both the column and the term so the comparison is case-insensitive
  • Extract the term normalisation into searchTermForTag so the behaviour can
    be covered by a unit test without standing up a database
  • Add that test

Reproduced against 2.0.2 on PostgreSQL 18.

The search term was formatted into LOWER(%s) and passed as the *value* of the
LIKE, so the function name ended up inside the pattern:

    slug_name LIKE '%LOWER(coco)%'

That can never match. Only the display_name clause did any work, and LIKE is
case-sensitive on Postgres, so searching a tag by the name it is written in
returns nothing:

    slug_name=Coco  -> matches
    slug_name=coco  -> no match

Tags are lower case by convention, so lower case is what users type, and the
filter appears to report that no such tag exists.

Lower both sides instead. The term normalisation is extracted so it can be
covered by a test without a database.
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.

1 participant