Browse Source

Fix `tagged` param not being normalized before querying tags (#10249)

pull/4/head
Eugen Rochko 5 years ago
committed by GitHub
parent
commit
06663fcf87
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 4 deletions
  1. +7
    -1
      app/controllers/accounts_controller.rb
  2. +7
    -1
      app/controllers/api/v1/accounts/statuses_controller.rb
  3. +1
    -1
      app/controllers/api/v1/timelines/tag_controller.rb
  4. +1
    -1
      app/controllers/tags_controller.rb
  5. +8
    -0
      app/models/tag.rb

+ 7
- 1
app/controllers/accounts_controller.rb View 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

+ 7
- 1
app/controllers/api/v1/accounts/statuses_controller.rb View 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)

+ 1
- 1
app/controllers/api/v1/timelines/tag_controller.rb View 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

+ 1
- 1
app/controllers/tags_controller.rb View 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

+ 8
- 0
app/models/tag.rb View 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

Loading…
Cancel
Save