Skip to content
This repository was archived by the owner on Jan 16, 2026. It is now read-only.

Commit 8fc1c77

Browse files
Gargronacid-chicken
authored andcommitted
Fix only one middle dot being recognized in hashtags (mastodon#11345)
Fix mastodon#10934
1 parent 403fcca commit 8fc1c77

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
@@ -16,7 +16,7 @@ class Tag < ApplicationRecord
1616

1717
has_one :account_tag_stat, dependent: :destroy
1818

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

2222
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)