Skip to content

Commit

Permalink
Fix only one middle dot being recognized in hashtags (#11345)
Browse files Browse the repository at this point in the history
Fix #10934
  • Loading branch information
Gargron committed Aug 9, 2019
1 parent 212848b commit 8c445c8
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion app/models/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class Tag < ApplicationRecord
has_many :featured_tags, dependent: :destroy, inverse_of: :tag
has_one :account_tag_stat, dependent: :destroy

HASHTAG_NAME_RE = '[[:word:]_]*[[:alpha:]_·][[:word:]_]*'
HASHTAG_NAME_RE = '[[:word:]_][[:word:]_]*[[:alpha:]_·]*[[:word:]_·]*[[:word:]_]'
HASHTAG_RE = /(?:^|[^\/\)\w])#(#{HASHTAG_NAME_RE})/i

validates :name, presence: true, uniqueness: true, format: { with: /\A#{HASHTAG_NAME_RE}\z/i }
Expand Down
38 changes: 37 additions & 1 deletion spec/models/tag_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,43 @@
end

it 'matches #aesthetic' do
expect(subject.match('this is #aesthetic')).to_not be_nil
expect(subject.match('this is #aesthetic').to_s).to eq ' #aesthetic'
end

it 'matches digits at the start' do
expect(subject.match('hello #3d').to_s).to eq ' #3d'
end

it 'matches digits in the middle' do
expect(subject.match('hello #l33ts35k').to_s).to eq ' #l33ts35k'
end

it 'matches digits at the end' do
expect(subject.match('hello #world2016').to_s).to eq ' #world2016'
end

it 'matches underscores at the beginning' do
expect(subject.match('hello #_test').to_s).to eq ' #_test'
end

it 'matches underscores at the end' do
expect(subject.match('hello #test_').to_s).to eq ' #test_'
end

it 'matches underscores in the middle' do
expect(subject.match('hello #one_two_three').to_s).to eq ' #one_two_three'
end

it 'matches middle dots' do
expect(subject.match('hello #one·two·three').to_s).to eq ' #one·two·three'
end

it 'does not match middle dots at the start' do
expect(subject.match('hello #·one·two·three')).to be_nil
end

it 'does not match middle dots at the end' do
expect(subject.match('hello #one·two·three·').to_s).to eq ' #one·two·three'
end
end

Expand Down

0 comments on commit 8c445c8

Please sign in to comment.