Skip to content

Commit 6335dd0

Browse files
authored
Fix tagged param not being normalized before querying tags (mastodon#10249)
1 parent 49bdcb6 commit 6335dd0

5 files changed

Lines changed: 24 additions & 4 deletions

File tree

app/controllers/accounts_controller.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,13 @@ def no_replies_scope
8080
end
8181

8282
def hashtag_scope
83-
Status.tagged_with(Tag.find_by(name: params[:tag].downcase)&.id)
83+
tag = Tag.find_normalized(params[:tag])
84+
85+
if tag
86+
Status.tagged_with(tag.id)
87+
else
88+
Status.none
89+
end
8490
end
8591

8692
def set_account

app/controllers/api/v1/accounts/statuses_controller.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,13 @@ def no_reblogs_scope
6969
end
7070

7171
def hashtag_scope
72-
Status.tagged_with(Tag.find_by(name: params[:tagged])&.id)
72+
tag = Tag.find_normalized(params[:tagged])
73+
74+
if tag
75+
Status.tagged_with(tag.id)
76+
else
77+
Status.none
78+
end
7379
end
7480

7581
def pagination_params(core_params)

app/controllers/api/v1/timelines/tag_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def show
1414
private
1515

1616
def load_tag
17-
@tag = Tag.find_by(name: params[:id].downcase)
17+
@tag = Tag.find_normalized(params[:id])
1818
end
1919

2020
def load_statuses

app/controllers/tags_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class TagsController < ApplicationController
99
before_action :set_instance_presenter
1010

1111
def show
12-
@tag = Tag.find_by!(name: params[:id].downcase)
12+
@tag = Tag.find_normalized!(params[:id])
1313

1414
respond_to do |format|
1515
format.html do

app/models/tag.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,14 @@ def search_for(term, limit = 5, offset = 0)
7272
.limit(limit)
7373
.offset(offset)
7474
end
75+
76+
def find_normalized(name)
77+
find_by(name: name.mb_chars.downcase.to_s)
78+
end
79+
80+
def find_normalized!(name)
81+
find_normalized(name) || raise(ActiveRecord::RecordNotFound)
82+
end
7583
end
7684

7785
private

0 commit comments

Comments
 (0)