def testConstructor(self): from AccessControl.tainted import TaintedBytes if six.PY2: self.assertRaises(ValueError, TaintedBytes, [60]) if six.PY3: self.assertEqual(TaintedBytes(60), b'<') self.assertEqual(TaintedBytes(32), b' ') self.assertEqual(TaintedBytes(b'abc'), b'abc') self.assertRaises(ValueError, TaintedBytes, u"abc")
def test_find_text_tainted(self): # Make sure ZopeFind can handle "Tainted" text for searches # Tainted strings are created when the publisher sees what appears # to be HTML code in the input, e.g. when you enter a HTML tag into # the Find tab form in "containing" from AccessControl.tainted import TaintedBytes from AccessControl.tainted import TaintedString findme = 'findme' self.base['doc1'] = DummyItem('doc1', text=findme) self.base['doc2'] = DummyItem('doc2', text=findme) tainted_string = TaintedString(findme) res = self.base.ZopeFind(self.base, obj_searchterm=tainted_string) self.assertEqual(len(res), 2) self.assertEqual(set([x[0] for x in res]), set(['doc1', 'doc2'])) tainted_bytes = TaintedBytes(six.b(findme)) res = self.base.ZopeFind(self.base, obj_searchterm=tainted_bytes) self.assertEqual(len(res), 2) self.assertEqual(set([x[0] for x in res]), set(['doc1', 'doc2']))