changeset 91:a71a58df6bf5 trunk

Some subtle fixes to generation and sanitization.
author cmlenz
date Thu, 20 Jul 2006 16:55:26 +0000
parents c835e81c50af
children 01d36818bb3d
files markup/builder.py markup/core.py markup/tests/core.py
diffstat 3 files changed, 7 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/markup/builder.py
+++ b/markup/builder.py
@@ -70,7 +70,9 @@
                     for event in child.generate():
                         yield event
                 else:
-                    yield Stream.TEXT, unicode(child), (-1, -1)
+                    if not isinstance(child, basestring):
+                        child = unicode(child)
+                    yield Stream.TEXT, child, (-1, -1)
         return Stream(_generate())
 
 
--- a/markup/core.py
+++ b/markup/core.py
@@ -334,7 +334,7 @@
         from markup.filters import HTMLSanitizer
         from markup.input import HTMLParser
         text = StringIO(self.stripentities(keepxmlentities=True))
-        return Stream(HTMLSanitizer()(HTMLParser(text)))
+        return Markup(Stream(HTMLSanitizer()(HTMLParser(text))))
 
 
 escape = Markup.escape
--- a/markup/tests/core.py
+++ b/markup/tests/core.py
@@ -123,9 +123,9 @@
         markup = Markup('<SCRIPT SRC="http://example.com/"></SCRIPT>')
         self.assertEquals('', str(markup.sanitize()))
         markup = Markup('<SCR\0IPT>alert("foo")</SCR\0IPT>')
-        self.assertRaises(ParseError, markup.sanitize().render)
+        self.assertRaises(ParseError, markup.sanitize)
         markup = Markup('<SCRIPT&XYZ SRC="http://example.com/"></SCRIPT>')
-        self.assertRaises(ParseError, markup.sanitize().render)
+        self.assertRaises(ParseError, markup.sanitize)
 
     def test_sanitize_remove_onclick_attr(self):
         markup = Markup('<div onclick=\'alert("foo")\' />')
@@ -156,7 +156,7 @@
         self.assertEquals('<img/>', str(markup.sanitize()))
         # Grave accents (not parsed)
         markup = Markup('<IMG SRC=`javascript:alert("RSnake says, \'foo\'")`>')
-        self.assertRaises(ParseError, markup.sanitize().render)
+        self.assertRaises(ParseError, markup.sanitize)
         # Protocol encoded using UTF-8 numeric entities
         markup = Markup('<IMG SRC=\'&#106;&#97;&#118;&#97;&#115;&#99;&#114;&#105;'
                         '&#112;&#116;&#58;alert("foo")\'>')
Copyright (C) 2012-2017 Edgewall Software