]> cat aescling's git repositories - mastodon.git/commitdiff
Fix hashtags being split by ZWNJ character (#11821)
authorEugen Rochko <eugen@zeonfederated.com>
Fri, 13 Sep 2019 14:01:26 +0000 (16:01 +0200)
committerGitHub <noreply@github.com>
Fri, 13 Sep 2019 14:01:26 +0000 (16:01 +0200)
Fix #11761

app/models/tag.rb
spec/models/tag_spec.rb

index 135e0a0306fa41def1ac4307f0e69bc3ae868d00..a6aed0d68e281ea097ef7049020671921ee678cf 100644 (file)
@@ -25,8 +25,9 @@ class Tag < ApplicationRecord
   has_many :featured_tags, dependent: :destroy, inverse_of: :tag
   has_one :account_tag_stat, dependent: :destroy
 
-  HASHTAG_NAME_RE = '([[:word:]_][[:word:]_·]*[[:alpha:]_·][[:word:]_·]*[[:word:]_])|([[:word:]_]*[[:alpha:]][[:word:]_]*)'
-  HASHTAG_RE = /(?:^|[^\/\)\w])#(#{HASHTAG_NAME_RE})/i
+  HASHTAG_SEPARATORS = "_\u00B7\u200c"
+  HASHTAG_NAME_RE    = "([[:word:]_][[:word:]#{HASHTAG_SEPARATORS}]*[[:alpha:]#{HASHTAG_SEPARATORS}][[:word:]#{HASHTAG_SEPARATORS}]*[[:word:]_])|([[:word:]_]*[[:alpha:]][[:word:]_]*)"
+  HASHTAG_RE         = /(?:^|[^\/\)\w])#(#{HASHTAG_NAME_RE})/i
 
   validates :name, presence: true, format: { with: /\A(#{HASHTAG_NAME_RE})\z/i }
   validate :validate_name_change, if: -> { !new_record? && name_changed? }
index 2bb30fb57f762eee9f02bb296b9c1ef910d628da..df876593c9e026d9b1f0c103041a34719e112234 100644 (file)
@@ -62,6 +62,10 @@ RSpec.describe Tag, type: :model do
       expect(subject.match('hello #one·two·three').to_s).to eq ' #one·two·three'
     end
 
+    it 'matches ZWNJ' do
+      expect(subject.match('just add #نرم‌افزار and').to_s).to eq ' #نرم‌افزار'
+    end
+
     it 'does not match middle dots at the start' do
       expect(subject.match('hello #·one·two·three')).to be_nil
     end