changeset 280:ce848f7c41f1 trunk

The content of `<script>` and `<style>` elements is no longer escaped when serializing to HTML but declaring the XHTML namespace in the template.
author cmlenz
date Sat, 07 Oct 2006 19:18:05 +0000
parents a99666402b12
children faf7fc3cbacf
files ChangeLog genshi/output.py genshi/tests/output.py
diffstat 3 files changed, 38 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog
+++ b/ChangeLog
@@ -20,6 +20,8 @@
    The were erroneously using the namespace context of the elements being
    matched, where they should rather use the context in which they were
    defined.
+ * The content of `<script>` and `<style>` elements is no longer escaped when
+   serializing to HTML but declaring the XHTML namespace in the template.
 
 
 Version 0.3.1
--- a/genshi/output.py
+++ b/genshi/output.py
@@ -298,7 +298,10 @@
     <div><a href="foo"></a><br><hr noshade></div>
     """
 
-    _NOESCAPE_ELEMS = frozenset([QName('script'), QName('style')])
+    _NOESCAPE_ELEMS = frozenset([QName('script'),
+                                 QName('http://www.w3.org/1999/xhtml}script'),
+                                 QName('style'),
+                                 QName('http://www.w3.org/1999/xhtml}style')])
 
     def __init__(self, doctype=None, strip_whitespace=True):
         """Initialize the HTML serializer.
--- a/genshi/tests/output.py
+++ b/genshi/tests/output.py
@@ -110,6 +110,13 @@
         output = XML(text).render(XHTMLSerializer)
         self.assertEqual(text, output)
 
+    def test_script_escaping_with_namespace(self):
+        text = """<script xmlns="http://www.w3.org/1999/xhtml">/*<![CDATA[*/
+            if (1 < 2) { alert("Doh"); }
+        /*]]>*/</script>"""
+        output = XML(text).render(XHTMLSerializer)
+        self.assertEqual(text, output)
+
     def test_style_escaping(self):
         text = """<style>/*<![CDATA[*/
             html > body { display: none; }
@@ -117,6 +124,13 @@
         output = XML(text).render(XHTMLSerializer)
         self.assertEqual(text, output)
 
+    def test_style_escaping_with_namespace(self):
+        text = """<style xmlns="http://www.w3.org/1999/xhtml">/*<![CDATA[*/
+            html > body { display: none; }
+        /*]]>*/</style>"""
+        output = XML(text).render(XHTMLSerializer)
+        self.assertEqual(text, output)
+
     def test_embedded_svg(self):
         text = """<html xmlns="http://www.w3.org/1999/xhtml" xmlns:svg="http://www.w3.org/2000/svg">
           <body>
@@ -156,12 +170,30 @@
         self.assertEqual('<script>if (1 < 2) { alert("Doh"); }</script>',
                          output)
 
+    def test_script_escaping_with_namespace(self):
+        text = """<script xmlns="http://www.w3.org/1999/xhtml">
+            if (1 &lt; 2) { alert("Doh"); }
+        </script>"""
+        output = XML(text).render(HTMLSerializer)
+        self.assertEqual("""<script>
+            if (1 < 2) { alert("Doh"); }
+        </script>""", output)
+
     def test_style_escaping(self):
         text = '<style>html &gt; body { display: none; }</style>'
         output = XML(text).render(HTMLSerializer)
         self.assertEqual('<style>html > body { display: none; }</style>',
                          output)
 
+    def test_style_escaping_with_namespace(self):
+        text = """<style xmlns="http://www.w3.org/1999/xhtml">
+            html &gt; body { display: none; }
+        </style>"""
+        output = XML(text).render(HTMLSerializer)
+        self.assertEqual("""<style>
+            html > body { display: none; }
+        </style>""", output)
+
 
 class EmptyTagFilterTestCase(unittest.TestCase):
 
Copyright (C) 2012-2017 Edgewall Software