Skip to content
Snippets Groups Projects
Commit f2f34a87 authored by Angie Byron's avatar Angie Byron
Browse files

#362972 by tic2000 and stewsnooze: Have nofollow filter remove 'rel'...

#362972 by tic2000 and stewsnooze: Have nofollow filter remove 'rel' attributes instead of just adding rel='nofollow'.
parent 6a97ac17
No related branches found
No related tags found
2 merge requests!7452Issue #1797438. HTML5 validation is preventing form submit and not fully...,!789Issue #3210310: Adjust Database API to remove deprecated Drupal 9 code in Drupal 10
......@@ -728,7 +728,12 @@ function _filter_html($text, $format) {
$text = filter_xss($text, $allowed_tags);
if (variable_get("filter_html_nofollow_$format", FALSE)) {
$text = preg_replace('/<a([^>]+)>/i', '<a\\1 rel="nofollow">', $text);
$html_dom = filter_dom_load($text);
$links = $html_dom->getElementsByTagName('a');
foreach($links as $link) {
$link->setAttribute('rel', 'nofollow');
}
$text = filter_dom_serialize($html_dom);
}
return trim($text);
......
......@@ -475,6 +475,10 @@ class FilterUnitTest extends DrupalWebTestCase {
$f = _filter_html('<!--[if true]><a href="http://www.example.com/">text</a><![endif]-->', 'f');
$this->assertNormalized($f, 'rel="nofollow"', t('Spam deterrent evasion -- link within a comment.'));
$f = _filter_html('<a href="http://www.example.com/" rel="follow">text</a>', 'f');
$this->assertNoNormalized($f, 'rel="follow"', t('Spam deterrent evasion -- with rel set - rel="follow" removed.'));
$this->assertNormalized($f, 'rel="nofollow"', t('Spam deterrent evasion -- with rel set - rel="nofollow" added.'));
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment