Skip to content

Commit

Permalink
Fix tagged param not being normalized before querying tags (mastodo…
Browse files Browse the repository at this point in the history
  • Loading branch information
Gargron authored and hiyuki2578 committed Oct 2, 2019
1 parent e4afc8c commit 377eaf4
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 4 deletions.
8 changes: 7 additions & 1 deletion app/controllers/accounts_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,13 @@ def no_replies_scope
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
Expand Down
8 changes: 7 additions & 1 deletion app/controllers/api/v1/accounts/statuses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,13 @@ def no_reblogs_scope
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)
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/api/v1/timelines/tag_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ def show
private

def load_tag
@tag = Tag.find_by(name: params[:id].downcase)
@tag = Tag.find_normalized(params[:id])
end

def load_statuses
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/tags_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions app/models/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ def search_for(term, limit = 5, offset = 0)
.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
Expand Down

0 comments on commit 377eaf4

Please sign in to comment.