Commit f2f34a87 authored by webchick's avatar webchick

#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
......@@ -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.'));
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment