about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorEugen Rochko <eugen@zeonfederated.com>2019-02-09 20:13:11 +0100
committerGitHub <noreply@github.com>2019-02-09 20:13:11 +0100
commit016ad37bc8c9ca8bf8f872b8fee704a0388f575e (patch)
treefe0d5dac5073ca4bdd0fcb90518699f696473872 /app
parenta666d1e7edaa8a3da61ce23f648321f7aa61d03b (diff)
Fix URL linkifier grabbing full-width spaces and quotations (#9997)
Fix #9993
Fix #5654
Diffstat (limited to 'app')
-rw-r--r--app/lib/formatter.rb12
1 files changed, 11 insertions, 1 deletions
diff --git a/app/lib/formatter.rb b/app/lib/formatter.rb
index 6603b8df1..0653214f5 100644
--- a/app/lib/formatter.rb
+++ b/app/lib/formatter.rb
@@ -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