summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2009-08-15 06:45:31 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2009-08-15 06:45:31 +0000
commitf2f34a87f84b420cc5a5df16820e46b693cf911a (patch)
tree316cc44af02d022a314193f37f58db789a2b4dc0 /modules
parent6a97ac176e10f20022f13feb347e5ccc7bc04c0c (diff)
downloadbrdo-f2f34a87f84b420cc5a5df16820e46b693cf911a.tar.gz
brdo-f2f34a87f84b420cc5a5df16820e46b693cf911a.tar.bz2
#362972 by tic2000 and stewsnooze: Have nofollow filter remove 'rel' attributes instead of just adding rel='nofollow'.
Diffstat (limited to 'modules')
-rw-r--r--modules/filter/filter.module7
-rw-r--r--modules/filter/filter.test4
2 files changed, 10 insertions, 1 deletions
diff --git a/modules/filter/filter.module b/modules/filter/filter.module
index 945a90518..58a3bf4ab 100644
--- a/modules/filter/filter.module
+++ b/modules/filter/filter.module
@@ -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);
diff --git a/modules/filter/filter.test b/modules/filter/filter.test
index 4f74a1ae3..f73be063f 100644
--- a/modules/filter/filter.test
+++ b/modules/filter/filter.test
@@ -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.'));
}
/**