my $dom = Mojo::DOM->new($html);
$dom->find(join(', ', @bad_tags))->map('remove');
+
+ $dom->find("a[href]")->grep(\&_is_external_link)->map(attr => rel => 'nofollow');
$dom->find(join ', ', @valid_text_parent_tags)->map(sub {
my $node = shift;
$node->descendant_nodes->map(sub {
}
+sub _is_external_link {
+ # the urlbase, without the trailing /
+ state $urlbase = substr(Bugzilla->localconfig->urlbase, 0, -1);
+
+ return index($_->attr('href'), $urlbase) != 0;
+}
+
1;
use lib qw( . lib local/lib/perl5 );
use Bugzilla::Test::MockDB;
+use Bugzilla::Test::MockLocalconfig urlbase => 'http://bmo-web.vm/';
use Bugzilla::Test::MockParams (password_complexity => 'no_constraints');
use Mojo::DOM;
use Bugzilla;
is(
$parser->render_html('http://bmo-web.vm'),
- "<p><a href=\"http://bmo-web.vm\">http://bmo-web.vm</a></p>\n",
+ "<p><a href=\"http://bmo-web.vm\" rel=\"nofollow\">http://bmo-web.vm</a></p>\n",
'Autolink extension'
);