Fix ß bug in regexp for mentions and tags (#31122)
This commit is contained in:
parent
0fc738a323
commit
7b7d404efe
@ -66,7 +66,7 @@ class Account < ApplicationRecord
|
||||
BACKGROUND_REFRESH_INTERVAL = 1.week.freeze
|
||||
|
||||
USERNAME_RE = /[a-z0-9_]+([a-z0-9_.-]+[a-z0-9_]+)?/i
|
||||
MENTION_RE = %r{(?<![=/[:word:]])@((#{USERNAME_RE})(?:@[[:word:].-]+[[:word:]]+)?)}i
|
||||
MENTION_RE = %r{(?<![=/[:word:]])@((#{USERNAME_RE})(?:@[[:word:].-]+[[:word:]]+)?)}
|
||||
URL_PREFIX_RE = %r{\Ahttp(s?)://[^/]+}
|
||||
USERNAME_ONLY_RE = /\A#{USERNAME_RE}\z/i
|
||||
|
||||
|
@ -35,7 +35,7 @@ class Tag < ApplicationRecord
|
||||
HASHTAG_LAST_SEQUENCE = '([[:word:]_]*[[:alpha:]][[:word:]_]*)'
|
||||
HASHTAG_NAME_PAT = "#{HASHTAG_FIRST_SEQUENCE}|#{HASHTAG_LAST_SEQUENCE}"
|
||||
|
||||
HASHTAG_RE = %r{(?<![=/)\p{Alnum}])#(#{HASHTAG_NAME_PAT})}i
|
||||
HASHTAG_RE = %r{(?<![=/)\p{Alnum}])#(#{HASHTAG_NAME_PAT})}
|
||||
HASHTAG_NAME_RE = /\A(#{HASHTAG_NAME_PAT})\z/i
|
||||
HASHTAG_INVALID_CHARS_RE = /[^[:alnum:]#{HASHTAG_SEPARATORS}]/
|
||||
|
||||
|
@ -703,6 +703,14 @@ RSpec.describe Account do
|
||||
it 'does not match URL query string' do
|
||||
expect(subject.match('https://example.com/?x=@alice')).to be_nil
|
||||
end
|
||||
|
||||
it 'matches usernames immediately following the letter ß' do
|
||||
expect(subject.match('Hello toß @alice from me')[1]).to eq 'alice'
|
||||
end
|
||||
|
||||
it 'matches usernames containing uppercase characters' do
|
||||
expect(subject.match('Hello to @aLice@Example.com from me')[1]).to eq 'aLice@Example.com'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'validations' do
|
||||
|
@ -95,6 +95,14 @@ RSpec.describe Tag do
|
||||
it 'does not match purely-numeric hashtags' do
|
||||
expect(subject.match('hello #0123456')).to be_nil
|
||||
end
|
||||
|
||||
it 'matches hashtags immediately following the letter ß' do
|
||||
expect(subject.match('Hello toß #ruby').to_s).to eq '#ruby'
|
||||
end
|
||||
|
||||
it 'matches hashtags containing uppercase characters' do
|
||||
expect(subject.match('Hello #rubyOnRails').to_s).to eq '#rubyOnRails'
|
||||
end
|
||||
end
|
||||
|
||||
describe '#to_param' do
|
||||
|
Loading…
Reference in New Issue
Block a user