mirror of
https://github.com/mastodon/mastodon.git
synced 2025-09-05 17:31:12 +00:00
Merge 4e99637115
into 14cb5ff881
This commit is contained in:
commit
d04d387615
|
@ -67,6 +67,8 @@ class Tag < ApplicationRecord
|
||||||
}
|
}
|
||||||
scope :matches_name, ->(term) { where(arel_table[:name].lower.matches(arel_table.lower("#{sanitize_sql_like(Tag.normalize(term))}%"), nil, true)) } # Search with case-sensitive to use B-tree index
|
scope :matches_name, ->(term) { where(arel_table[:name].lower.matches(arel_table.lower("#{sanitize_sql_like(Tag.normalize(term))}%"), nil, true)) } # Search with case-sensitive to use B-tree index
|
||||||
|
|
||||||
|
normalizes :display_name, with: ->(value) { value.gsub(HASHTAG_INVALID_CHARS_RE, '') }
|
||||||
|
|
||||||
update_index('tags', :self)
|
update_index('tags', :self)
|
||||||
|
|
||||||
def to_param
|
def to_param
|
||||||
|
@ -112,8 +114,7 @@ class Tag < ApplicationRecord
|
||||||
names = Array(name_or_names).map { |str| [normalize(str), str] }.uniq(&:first)
|
names = Array(name_or_names).map { |str| [normalize(str), str] }.uniq(&:first)
|
||||||
|
|
||||||
names.map do |(normalized_name, display_name)|
|
names.map do |(normalized_name, display_name)|
|
||||||
tag = matching_name(normalized_name).first || create(name: normalized_name,
|
tag = matching_name(normalized_name).first || create(name: normalized_name, display_name:)
|
||||||
display_name: display_name.gsub(HASHTAG_INVALID_CHARS_RE, ''))
|
|
||||||
|
|
||||||
yield tag if block_given?
|
yield tag if block_given?
|
||||||
|
|
||||||
|
|
|
@ -57,6 +57,11 @@ RSpec.describe Tag do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
describe 'Normalizations' do
|
||||||
|
it { is_expected.to normalize(:display_name).from('#HelloWorld').to('HelloWorld') }
|
||||||
|
it { is_expected.to normalize(:display_name).from('Hello❤️World').to('HelloWorld') }
|
||||||
|
end
|
||||||
|
|
||||||
describe 'HASHTAG_RE' do
|
describe 'HASHTAG_RE' do
|
||||||
subject { described_class::HASHTAG_RE }
|
subject { described_class::HASHTAG_RE }
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user