]> cat aescling's git repositories - mastodon.git/commitdiff
Fix `tagged` param not being normalized before querying tags (#10249)
authorEugen Rochko <eugen@zeonfederated.com>
Wed, 13 Mar 2019 12:02:13 +0000 (13:02 +0100)
committerGitHub <noreply@github.com>
Wed, 13 Mar 2019 12:02:13 +0000 (13:02 +0100)
app/controllers/accounts_controller.rb
app/controllers/api/v1/accounts/statuses_controller.rb
app/controllers/api/v1/timelines/tag_controller.rb
app/controllers/tags_controller.rb
app/models/tag.rb

index cad2ecf3fea1c31001719aa31367791e74b5933d..dfbe5bffcf3967f2e3b8b72e687ed9b4def7b3ec 100644 (file)
@@ -80,7 +80,13 @@ class AccountsController < ApplicationController
   end
 
   def hashtag_scope
-    Status.tagged_with(Tag.find_by(name: params[:tag].downcase)&.id)
+    tag = Tag.find_normalized(params[:tag])
+
+    if tag
+      Status.tagged_with(tag.id)
+    else
+      Status.none
+    end
   end
 
   def set_account
index ed10f3f6a7e52be0340230d0bb589fe6acf2db32..8cd8f8e79966b19afc354ccc3baaa8bc273086ec 100644 (file)
@@ -69,7 +69,13 @@ class Api::V1::Accounts::StatusesController < Api::BaseController
   end
 
   def hashtag_scope
-    Status.tagged_with(Tag.find_by(name: params[:tagged])&.id)
+    tag = Tag.find_normalized(params[:tagged])
+
+    if tag
+      Status.tagged_with(tag.id)
+    else
+      Status.none
+    end
   end
 
   def pagination_params(core_params)
index 92c32c1784b2e2c56a689c0284294f0c26a298a0..9adc4ad29129242480e3b33f54ffa9cf97251634 100644 (file)
@@ -14,7 +14,7 @@ class Api::V1::Timelines::TagController < Api::BaseController
   private
 
   def load_tag
-    @tag = Tag.find_by(name: params[:id].downcase)
+    @tag = Tag.find_normalized(params[:id])
   end
 
   def load_statuses
index 729553e1e7f5e10328b8e9333ef24e598ad8f6c8..66b18490117833a176ded1f937776f226ec348b1 100644 (file)
@@ -9,7 +9,7 @@ class TagsController < ApplicationController
   before_action :set_instance_presenter
 
   def show
-    @tag = Tag.find_by!(name: params[:id].downcase)
+    @tag = Tag.find_normalized!(params[:id])
 
     respond_to do |format|
       format.html do
index 788a678bdee076f3eaa071942b883e7b035ff9ee..7db76d157b00044f20a6770e6ec367f8aea942b9 100644 (file)
@@ -72,6 +72,14 @@ class Tag < ApplicationRecord
          .limit(limit)
          .offset(offset)
     end
+
+    def find_normalized(name)
+      find_by(name: name.mb_chars.downcase.to_s)
+    end
+
+    def find_normalized!(name)
+      find_normalized(name) || raise(ActiveRecord::RecordNotFound)
+    end
   end
 
   private