about summary refs log tree commit diff
path: root/app/models
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2020-11-12 18:35:23 +0100
committerGitHub <noreply@github.com>2020-11-12 18:35:23 +0100
commit9870b175b477bbc984fc7945f1ebe07e3f2b0053 (patch)
tree8705307fed3d5de28ade8255c3b985c54637fd19 /app/models
parent148ce97e21092500a2abeb87f6dc3c0adf5f28e4 (diff)
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
Diffstat (limited to 'app/models')
-rw-r--r--app/models/tag.rb2
1 files changed, 1 insertions, 1 deletions
diff --git a/app/models/tag.rb b/app/models/tag.rb
index df2f86d95..bb93a52e2 100644
--- a/app/models/tag.rb
+++ b/app/models/tag.rb
@@ -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]