diff --git a/lib/fdroid/Package.rb b/lib/fdroid/Package.rb index e1aca7d0914092ea9ab8922e3f349b2a2bf49c65..82adfd982752ae0ba5d9ffe11b5ed139a7afb791 100644 --- a/lib/fdroid/Package.rb +++ b/lib/fdroid/Package.rb @@ -47,9 +47,19 @@ module Loofah::Scrubbers end end + if node.keys.empty? + node.name = '_remove' + Strip.new.scrub(node) + return STOP + end + begin url = URI.parse(node.attributes['href'].to_s) - return STOP if url.host == nil || url.host.empty? || url.host == 'f-droid.org' + # the only official domain names used for this site, everything else redirects + return STOP if (url.host == nil || + url.host.empty? || + url.host == 'f-droid.org' || + url.host == 'staging.f-droid.org') rescue URI::Error # treat this URL as external end @@ -58,6 +68,7 @@ module Loofah::Scrubbers append_attribute(node, 'rel', 'nofollow') append_attribute(node, 'rel', 'noopener') append_attribute(node, 'target', '_blank') + node.after Nokogiri::XML::Text.new("🔗", node.document) return STOP end end diff --git a/spec/lib/fdroid/FDroidIndex_spec.rb b/spec/lib/fdroid/FDroidIndex_spec.rb index d4bce9023e055724414581d12fdf7437cf48eaa6..7f5268301af4929af1ee16f20a84056139fde2cb 100644 --- a/spec/lib/fdroid/FDroidIndex_spec.rb +++ b/spec/lib/fdroid/FDroidIndex_spec.rb @@ -178,12 +178,18 @@ here" END output = <<~'END'.gsub("\n", '
') bold text - link + link🔗 END scrubbed = Package.process_package_description(input) expect(scrubbed).to eql(output) end + it 'strips w/o href' do + text = 'link' + scrubbed = Package.process_package_description(text) + expect(scrubbed).to eql('link') + end + it 'sanitises' do input = { 'description' => 'bold/b>',