test
', bleach.clean('test
', tags=['p'])) def test_no_href_links(): s = 'x' eq_(s, bleach.linkify(s)) def test_weird_strings(): s = '3' eq_(bleach.clean(s), '') def test_xml_render(): parser = html5lib.HTMLParser() eq_(bleach._render(parser.parseFragment('')), '') def test_stripping(): eq_('a test with html tags', bleach.clean('a test with html tags', strip=True)) eq_('a test with html tags', bleach.clean('a test with ' 'html tags', strip=True)) s = '' eq_('link text
', bleach.clean(s, tags=['p'], strip=True)) s = 'multiply nested text
' eq_('multiply nested text
', bleach.clean(s, tags=['p'], strip=True)) s = ('') eq_('', bleach.clean(s, tags=['p', 'a'], strip=True)) def test_allowed_styles(): ATTR = ['style'] STYLE = ['color'] blank = '' s = '' eq_(blank, bleach.clean('', attributes=ATTR)) eq_(s, bleach.clean(s, attributes=ATTR, styles=STYLE)) eq_(s, bleach.clean('', attributes=ATTR, styles=STYLE)) def test_idempotent(): """Make sure that applying the filter twice doesn't change anything.""" dirty = 'invalid & < extra http://link.com' clean = bleach.clean(dirty) eq_(clean, bleach.clean(clean)) linked = bleach.linkify(dirty) eq_(linked, bleach.linkify(linked)) def test_rel_already_there(): """Make sure rel attribute is updated not replaced""" linked = ('Click ' 'here.') link_good = (('Click ' 'here.'), ('Click ' 'here.')) in_(link_good, bleach.linkify(linked)) in_(link_good, bleach.linkify(link_good[0])) def test_lowercase_html(): """We should output lowercase HTML.""" dirty = 'BAR' clean = 'BAR' eq_(clean, bleach.clean(dirty, attributes=['class'])) def test_wildcard_attributes(): ATTR = { '*': ['id'], 'img': ['src'], } TAG = ['img', 'em'] dirty = ('both can have ' '') clean = ('both can have ', 'both can have ') in_(clean, bleach.clean(dirty, tags=TAG, attributes=ATTR)) def test_sarcasm(): """Jokes should crash.