about summary refs log tree commit diff
diff options
context:
space:
mode:
authormultiple creatures <dev@multiple-creature.party>2019-07-20 23:19:26 -0500
committermultiple creatures <dev@multiple-creature.party>2019-07-20 23:25:46 -0500
commitc4600411f73138489e3c3870de1693a297f4fe46 (patch)
tree1c16f90063b4420296f141bca8b670539ef0fcfa
parent19fc6952b2a8477bd0ac41a0162248012761ecba (diff)
fix anchor tagger filename matching
-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