mirror of
https://framagit.org/tykayn/mastodon.git
synced 2023-08-25 08:33:12 +02:00
Fix possible inconsistencies in tag search (#14906)
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
This commit is contained in:
parent
148ce97e21
commit
9870b175b4
@ -126,7 +126,7 @@ class Tag < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def search_for(term, limit = 5, offset = 0, options = {})
|
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) + '%'
|
pattern = sanitize_sql_like(normalized_term) + '%'
|
||||||
query = Tag.listable.where(arel_table[:name].lower.matches(pattern))
|
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]
|
query = query.where(arel_table[:name].lower.eq(normalized_term).or(arel_table[:reviewed_at].not_eq(nil))) if options[:exclude_unreviewed]
|
||||||
|
Loading…
Reference in New Issue
Block a user