diff --git a/app/presenters/decidim/decidim_awesome/user_autoblock_scores_presenter.rb b/app/presenters/decidim/decidim_awesome/user_autoblock_scores_presenter.rb index 85084157..6a3dafc5 100644 --- a/app/presenters/decidim/decidim_awesome/user_autoblock_scores_presenter.rb +++ b/app/presenters/decidim/decidim_awesome/user_autoblock_scores_presenter.rb @@ -82,6 +82,8 @@ def calculate_positive(rule) end class LinksParser + UNWISE_REGEXP = /[{}|\\^\[\]`]/ + attr_reader :allowlist, :blocklist def initialize(text, allowlist: [], blocklist: []) @@ -93,7 +95,8 @@ def initialize(text, allowlist: [], blocklist: []) def filtered_links @filtered_links ||= links.reject do |link| - hostname = URI.parse(link).hostname + hostname = URI.parse(clean_link(link)).hostname + hostname.blank? || (allowlist.present? && allowlist.any? { |name| name == hostname }) || (blocklist.present? && blocklist.all? { |name| name != hostname }) @@ -107,6 +110,14 @@ def links def has_blocked_links? filtered_links.present? end + + # This method removes characters from link producing errors trying + # to parse them + def clean_link(link) + return link unless UNWISE_REGEXP.match?(link) + + link.split(UNWISE_REGEXP).first + end end class UserActivities