]> cat aescling's git repositories - mastodon.git/commitdiff
Fix possible inconsistencies in tag search (#14906)
authorThibG <thib@sitedethib.com>
Thu, 12 Nov 2020 17:35:23 +0000 (18:35 +0100)
committerGitHub <noreply@github.com>
Thu, 12 Nov 2020 17:35:23 +0000 (18:35 +0100)
Do not downcase the queried tag before passing it to postgres when searching:
- tags are not downcased on creation
- `arel_table[:name].lower.matches(pattern)` generates an ILIKE anyway
- if Postgres and Rails happen to use different case-folding rules,
  downcasing before query but not before insertion may mean that some
  tags with some casings are not searchable

app/models/tag.rb

index df2f86d95208b58c877ed0fd42a2d63868bd627f..bb93a52e2e56e6717a6b50c651a069e8367f50a6 100644 (file)
@@ -126,7 +126,7 @@ class Tag < ApplicationRecord
     end
 
     def search_for(term, limit = 5, offset = 0, options = {})
-      normalized_term = normalize(term.strip).mb_chars.downcase.to_s
+      normalized_term = normalize(term.strip)
       pattern         = sanitize_sql_like(normalized_term) + '%'
       query           = Tag.listable.where(arel_table[:name].lower.matches(pattern))
       query           = query.where(arel_table[:name].lower.eq(normalized_term).or(arel_table[:reviewed_at].not_eq(nil))) if options[:exclude_unreviewed]