about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--app/lib/sanitize_config.rb22
1 files changed, 10 insertions, 12 deletions
diff --git a/app/lib/sanitize_config.rb b/app/lib/sanitize_config.rb
index cd2299e8b..697d88fd3 100644
--- a/app/lib/sanitize_config.rb
+++ b/app/lib/sanitize_config.rb
@@ -43,30 +43,28 @@ class Sanitize
       text = node.text.strip
       return if href == text
 
-      # try to detect filenames
-      href_filename = href.rpartition('/')[-1]
-      url_filename = text.rpartition('/')[-1]
+      # strip ellipse & replace keyword search obscuring
+      text = text.sub(/ *(?:\u2026|\.\.\.)\Z/, '').gsub(/ dot /i, '.').gsub(/[\u200b-\u200d\ufeff\u200e\u200f]/, '')
 
+      # href now matches text without obscuring?
+      return if href == text
+
+      # try to detect filenames
+      href_filename = '/'.in?(href) ? href.rpartition('/')[2] : nil
       unless href_filename.blank?
-        if url_filename == href_filename
+        if text == href_filename
           node.inner_html = "\xf0\x9f\x93\x8e #{node.inner_html}"
           return
         end
 
         # many fedi servers obfuscate media filenames
-        ext = url_filename.rpartition('.')[-1]
-        if ext.downcase.in?(MEDIA_EXTENSIONS) && ext == href_filename.rpartition('.')[-1]
+        ext = text.rpartition('.')[-1]
+        if ext.downcase.in?(MEDIA_EXTENSIONS) && ext == href_filename.rpartition('.')[2]
           node.inner_html = "\xf0\x9f\x93\x8e #{node.inner_html}"
           return
         end
       end
 
-      # strip ellipse & replace keyword search obscuring
-      text = text.sub(/ *(?:\u2026|\.\.\.)\Z/, '').gsub(/ dot /i, '.').gsub(/[\u200b-\u200d\ufeff\u200e\u200f]/, '')
-
-      # href now matches text without obscuring?
-      return if href == text
-
       # grab first url from link text
       first_url = text.scan(/[\w\-]+\.[\w\-]+(?:\.[\w\-]+)*\S*/).first