From 2c510ee00a9fb4141a428d9a21dbd561171b3409 Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Sun, 22 Mar 2020 16:59:29 +0100 Subject: Fix glitch-soc marking every link in toots as a tag Fixes #1281 --- app/lib/formatter.rb | 2 +- app/lib/sanitize_config.rb | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) (limited to 'app/lib') diff --git a/app/lib/formatter.rb b/app/lib/formatter.rb index fcc99d009..b7a0286d2 100644 --- a/app/lib/formatter.rb +++ b/app/lib/formatter.rb @@ -131,7 +131,7 @@ class Formatter end def link_url(url) - "#{link_html(url)}" + "#{link_html(url)}" end private diff --git a/app/lib/sanitize_config.rb b/app/lib/sanitize_config.rb index e3fc94ba6..8bbcca4ce 100644 --- a/app/lib/sanitize_config.rb +++ b/app/lib/sanitize_config.rb @@ -54,6 +54,15 @@ class Sanitize end end + LINK_REL_TRANSFORMER = lambda do |env| + return unless env[:node_name] == 'a' + + node = env[:node] + + rel = (node['rel'] || '').split(' ') & ['tag'] + node['rel'] = (['nofollow', 'noopener', 'noreferrer'] + rel).join(' ') + end + UNSUPPORTED_HREF_TRANSFORMER = lambda do |env| return unless env[:node_name] == 'a' @@ -82,7 +91,6 @@ class Sanitize add_attributes: { 'a' => { - 'rel' => 'nofollow noopener tag noreferrer', 'target' => '_blank', }, }, @@ -95,6 +103,7 @@ class Sanitize transformers: [ CLASS_WHITELIST_TRANSFORMER, IMG_TAG_TRANSFORMER, + LINK_REL_TRANSFORMER, UNSUPPORTED_HREF_TRANSFORMER, ] ) -- cgit