Skip to content

Commit 8c445c8

Browse files
committed
Fix only one middle dot being recognized in hashtags (#11345)
Fix #10934
1 parent 212848b commit 8c445c8

2 files changed

Lines changed: 38 additions & 2 deletions

File tree

app/models/tag.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class Tag < ApplicationRecord
1717
has_many :featured_tags, dependent: :destroy, inverse_of: :tag
1818
has_one :account_tag_stat, dependent: :destroy
1919

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

2323
validates :name, presence: true, uniqueness: true, format: { with: /\A#{HASHTAG_NAME_RE}\z/i }

spec/models/tag_spec.rb

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,43 @@
3131
end
3232

3333
it 'matches #aesthetic' do
34-
expect(subject.match('this is #aesthetic')).to_not be_nil
34+
expect(subject.match('this is #aesthetic').to_s).to eq ' #aesthetic'
35+
end
36+
37+
it 'matches digits at the start' do
38+
expect(subject.match('hello #3d').to_s).to eq ' #3d'
39+
end
40+
41+
it 'matches digits in the middle' do
42+
expect(subject.match('hello #l33ts35k').to_s).to eq ' #l33ts35k'
43+
end
44+
45+
it 'matches digits at the end' do
46+
expect(subject.match('hello #world2016').to_s).to eq ' #world2016'
47+
end
48+
49+
it 'matches underscores at the beginning' do
50+
expect(subject.match('hello #_test').to_s).to eq ' #_test'
51+
end
52+
53+
it 'matches underscores at the end' do
54+
expect(subject.match('hello #test_').to_s).to eq ' #test_'
55+
end
56+
57+
it 'matches underscores in the middle' do
58+
expect(subject.match('hello #one_two_three').to_s).to eq ' #one_two_three'
59+
end
60+
61+
it 'matches middle dots' do
62+
expect(subject.match('hello #one·two·three').to_s).to eq ' #one·two·three'
63+
end
64+
65+
it 'does not match middle dots at the start' do
66+
expect(subject.match('hello #·one·two·three')).to be_nil
67+
end
68+
69+
it 'does not match middle dots at the end' do
70+
expect(subject.match('hello #one·two·three·').to_s).to eq ' #one·two·three'
3571
end
3672
end
3773

0 commit comments

Comments
 (0)