Rev 6: Check that we use the safety rawHTML function. in http://bzr.arbash-meinel.com/branches/bzr/extra/moin_graphviz

John Arbash Meinel john at arbash-meinel.com
Tue Apr 3 00:53:02 BST 2007


At http://bzr.arbash-meinel.com/branches/bzr/extra/moin_graphviz

------------------------------------------------------------
revno: 6
revision-id: john at arbash-meinel.com-20070402235258-g9rga4lgdmofatpy
parent: john at arbash-meinel.com-20070402234736-fi7soeo351qgdxmy
committer: John Arbash Meinel <john at arbash-meinel.com>
branch nick: moin_graphviz
timestamp: Mon 2007-04-02 18:52:58 -0500
message:
  Check that we use the safety rawHTML function.
modified:
  graphviz.py                    graphviz.py-20070402222439-3qloodrjtlsuaz1o-1
  test_graphviz.py               test_graphviz.py-20070402223544-kez8ooyxqh1wx5w0-1
-------------- next part --------------
=== modified file 'graphviz.py'
--- a/graphviz.py	2007-04-02 23:47:36 +0000
+++ b/graphviz.py	2007-04-02 23:52:58 +0000
@@ -66,9 +66,9 @@
 
     def format(self, formatter):
         """Send the text."""
-        self.request.write('<img src="data:image/png;base64,')
-        self.request.write(self._create_b64_png())
-        self.request.write('" alt="Graphviz Image" />')
+        img_str = ('<img src="data:image/png;base64,%s"'
+                   ' alt="Graphviz Image" />') % (self._create_b64_png(),)
+        self.request.write(formatter.rawHTML(img_str))
 
 
 def test_suite():

=== modified file 'test_graphviz.py'
--- a/test_graphviz.py	2007-04-02 23:47:36 +0000
+++ b/test_graphviz.py	2007-04-02 23:52:58 +0000
@@ -26,10 +26,10 @@
     """A Request object which conforms to what we need."""
 
     def __init__(self):
-        self.output = cStringIO.StringIO()
+        self._output = cStringIO.StringIO()
 
     def write(self, txt):
-        self.output.write(txt)
+        self._output.write(txt)
 
     def getText(self, txt): # Wrapper for i18n
         return txt
@@ -42,10 +42,11 @@
         self._actions = []
 
     def escapedText(self, txt):
-        self._actions(('escapedText', txt))
+        self._actions.append(('escapedText', txt))
 
     def rawHTML(self, txt):
-        self._actions(('rawHTML', txt))
+        self._actions.append(('rawHTML', txt))
+        return txt
 
 
 class ParserWithCommand(graphviz.Parser):
@@ -194,4 +195,17 @@
                             ' alt="Graphviz Image" />'
                             % (expected_base64_txt,))
         self.assertEqual(expected_img_txt,
-                         request.output.getvalue())
+                         request._output.getvalue())
+
+    def test_format_uses_rawHTML(self):
+        request = self.get_request()
+        p = ParserWithForcedPng('raw_txt', request=request)
+        expected_img_txt = ('<img src="data:image/png;base64,%s"'
+                            ' alt="Graphviz Image" />'
+                            % (p._create_b64_png(),))
+
+        formatter = self.get_formatter()
+        p.format(formatter)
+
+        self.assertEqual([('rawHTML', expected_img_txt)],
+                         formatter._actions)



More information about the bazaar-commits mailing list