Changes to html cleaner to make all external links nofollow to discourage forum spammers.
This commit is contained in:
parent
b368fa23b6
commit
fd681ed388
|
@ -144,7 +144,7 @@ class Html_cleaner(HTMLParser):
|
||||||
# "on" tags, like "onhover," would not be smart. Also be very careful
|
# "on" tags, like "onhover," would not be smart. Also be very careful
|
||||||
# of "background" and "style."
|
# of "background" and "style."
|
||||||
self.allowed_attributes = {
|
self.allowed_attributes = {
|
||||||
'a': [ 'href', 'target' ],
|
'a': [ 'href', 'target', 'rel' ],
|
||||||
'p': [ 'align' ],
|
'p': [ 'align' ],
|
||||||
'img': [ 'src', 'alt', 'border', 'title', "class" ],
|
'img': [ 'src', 'alt', 'border', 'title', "class" ],
|
||||||
'table': [ 'cellpadding', 'cellspacing', 'border', 'width', 'height' ],
|
'table': [ 'cellpadding', 'cellspacing', 'border', 'width', 'height' ],
|
||||||
|
@ -197,9 +197,13 @@ class Html_cleaner(HTMLParser):
|
||||||
else:
|
else:
|
||||||
bt += ' %s=%s' % \
|
bt += ' %s=%s' % \
|
||||||
(xssescape(attribute), quoteattr(attrs[attribute]))
|
(xssescape(attribute), quoteattr(attrs[attribute]))
|
||||||
if self.require_link_target and tag == "a" and not attrs.get( 'target' ) and \
|
if tag == "a" and \
|
||||||
( not attrs.get( 'href' ) or not self.NOTE_LINK_URL_PATTERN.search( attrs.get( 'href' ) ) ):
|
( not attrs.get( 'href' ) or not self.NOTE_LINK_URL_PATTERN.search( attrs.get( 'href' ) ) ):
|
||||||
bt += ' target="_new"'
|
if self.require_link_target and not attrs.get( 'target' ):
|
||||||
|
bt += ' target="_new"'
|
||||||
|
rel = attrs.get( 'rel' )
|
||||||
|
if not rel or rel != "nofollow":
|
||||||
|
bt += ' rel="nofollow"'
|
||||||
if bt == "<a" or bt == "<img":
|
if bt == "<a" or bt == "<img":
|
||||||
return
|
return
|
||||||
if tag in self.requires_no_close:
|
if tag in self.requires_no_close:
|
||||||
|
|
Reference in New Issue