about summary refs log tree commit diff
path: root/app
diff options
context:
space:
mode:
authorThibG <thib@sitedethib.com>2020-01-11 02:15:25 +0100
committerEugen Rochko <eugen@zeonfederated.com>2020-01-11 02:15:25 +0100
commitea436b355bd844c86a4f4ddfd204b9bf15a1db6c (patch)
treec33fd5501bf295573665740481a6d749a57bab35 /app
parente9ea09d17398763ead69ca845c7aefebf266d373 (diff)
Add support for linking XMPP URIs in toots (#12709)
* Fix wrong grouping in Twitter valid_url regex

* Add support for xmpp URIs

Fixes #9776

The difficult part is autolinking, because Twitter-text's extractor does
some pretty ad-hoc stuff to find things that “look like” URLs, and XMPP
URIs do not really match the assumptions of that lib, so it doesn't sound
wise to try to shoehorn it into the existing regex.

This is why I used a specific regex (very close, although slightly more
permissive than the RFC), and a specific scan function (a simplified version
of the generalized one from Twitter).

* Remove leading “xmpp:” from auto-linked text
Diffstat (limited to 'app')
-rw-r--r--app/lib/formatter.rb5
-rw-r--r--app/lib/sanitize_config.rb2
2 files changed, 4 insertions, 3 deletions
diff --git a/app/lib/formatter.rb b/app/lib/formatter.rb
index 6ba327614..c771dcaaa 100644
--- a/app/lib/formatter.rb
+++ b/app/lib/formatter.rb
@@ -245,8 +245,9 @@ class Formatter
     end
 
     standard = Extractor.extract_entities_with_indices(text, options)
+    xmpp = Extractor.extract_xmpp_uris_with_indices(text, options)
 
-    Extractor.remove_overlapping_entities(special + standard)
+    Extractor.remove_overlapping_entities(special + standard + xmpp)
   end
 
   def link_to_url(entity, options = {})
@@ -284,7 +285,7 @@ class Formatter
 
   def link_html(url)
     url    = Addressable::URI.parse(url).to_s
-    prefix = url.match(/\Ahttps?:\/\/(www\.)?/).to_s
+    prefix = url.match(/\A(https?:\/\/(www\.)?|xmpp:)/).to_s
     text   = url[prefix.length, 30]
     suffix = url[prefix.length + 30..-1]
     cutoff = url[prefix.length..-1].length > 30
diff --git a/app/lib/sanitize_config.rb b/app/lib/sanitize_config.rb
index 77045155e..e2480376e 100644
--- a/app/lib/sanitize_config.rb
+++ b/app/lib/sanitize_config.rb
@@ -2,7 +2,7 @@
 
 class Sanitize
   module Config
-    HTTP_PROTOCOLS ||= ['http', 'https', 'dat', 'dweb', 'ipfs', 'ipns', 'ssb', 'gopher', :relative].freeze
+    HTTP_PROTOCOLS ||= ['http', 'https', 'dat', 'dweb', 'ipfs', 'ipns', 'ssb', 'gopher', 'xmpp', :relative].freeze
 
     CLASS_WHITELIST_TRANSFORMER = lambda do |env|
       node = env[:node]