mirror of
https://github.com/mastodon/mastodon
synced 2024-12-12 21:58:20 +09:00
Fix some link anchors being recognized as hashtags (#27271)
This commit is contained in:
parent
aa69ca74ed
commit
cdedae6d63
@ -35,7 +35,7 @@ class Tag < ApplicationRecord
|
|||||||
HASHTAG_LAST_SEQUENCE = '([[:word:]_]*[[:alpha:]][[:word:]_]*)'
|
HASHTAG_LAST_SEQUENCE = '([[:word:]_]*[[:alpha:]][[:word:]_]*)'
|
||||||
HASHTAG_NAME_PAT = "#{HASHTAG_FIRST_SEQUENCE}|#{HASHTAG_LAST_SEQUENCE}"
|
HASHTAG_NAME_PAT = "#{HASHTAG_FIRST_SEQUENCE}|#{HASHTAG_LAST_SEQUENCE}"
|
||||||
|
|
||||||
HASHTAG_RE = %r{(?:^|[^/)\w])#(#{HASHTAG_NAME_PAT})}i
|
HASHTAG_RE = %r{(?<![=/)[:word]])#(#{HASHTAG_NAME_PAT})}i
|
||||||
HASHTAG_NAME_RE = /\A(#{HASHTAG_NAME_PAT})\z/i
|
HASHTAG_NAME_RE = /\A(#{HASHTAG_NAME_PAT})\z/i
|
||||||
HASHTAG_INVALID_CHARS_RE = /[^[:alnum:]#{HASHTAG_SEPARATORS}]/
|
HASHTAG_INVALID_CHARS_RE = /[^[:alnum:]#{HASHTAG_SEPARATORS}]/
|
||||||
|
|
||||||
|
@ -32,6 +32,10 @@ RSpec.describe Tag do
|
|||||||
expect(subject.match('https://en.wikipedia.org/wiki/Ghostbusters_(song)#Lawsuit')).to be_nil
|
expect(subject.match('https://en.wikipedia.org/wiki/Ghostbusters_(song)#Lawsuit')).to be_nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
it 'does not match URLs with hashtag-like anchors after an empty query parameter' do
|
||||||
|
expect(subject.match('https://en.wikipedia.org/wiki/Ghostbusters_(song)?foo=#Lawsuit')).to be_nil
|
||||||
|
end
|
||||||
|
|
||||||
it 'matches #aesthetic' do
|
it 'matches #aesthetic' do
|
||||||
expect(subject.match('this is #aesthetic').to_s).to eq '#aesthetic'
|
expect(subject.match('this is #aesthetic').to_s).to eq '#aesthetic'
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user