Fix URL linkifier grabbing full-width spaces and quotations (#9997)
Fix #9993 Fix #5654
This commit is contained in:
parent
a666d1e7ed
commit
016ad37bc8
3 changed files with 55 additions and 5 deletions
|
@ -199,12 +199,22 @@ class Formatter
|
|||
result.flatten.join
|
||||
end
|
||||
|
||||
UNICODE_ESCAPE_BLACKLIST_RE = /\p{Z}|\p{P}/
|
||||
|
||||
def utf8_friendly_extractor(text, options = {})
|
||||
old_to_new_index = [0]
|
||||
|
||||
escaped = text.chars.map do |c|
|
||||
output = c.ord.to_s(16).length > 2 ? CGI.escape(c) : c
|
||||
output = begin
|
||||
if c.ord.to_s(16).length > 2 && UNICODE_ESCAPE_BLACKLIST_RE.match(c).nil?
|
||||
CGI.escape(c)
|
||||
else
|
||||
c
|
||||
end
|
||||
end
|
||||
|
||||
old_to_new_index << old_to_new_index.last + output.length
|
||||
|
||||
output
|
||||
end.join
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue