]> granicus.if.org Git - python/commitdiff
Fixing the issue4860. Escaping embedded '"' character in js_output() method of Morsel.
authorSenthil Kumaran <orsenthil@gmail.com>
Thu, 2 Apr 2009 03:00:34 +0000 (03:00 +0000)
committerSenthil Kumaran <orsenthil@gmail.com>
Thu, 2 Apr 2009 03:00:34 +0000 (03:00 +0000)
Lib/Cookie.py
Lib/test/test_cookie.py

index b2f7427aa94f734ab2a34285917fb11eb0b2c4fc..1ccfd160a4997131a3ade8a73226388bb1f34f31 100644 (file)
@@ -477,7 +477,7 @@ class Morsel(dict):
         document.cookie = \"%s\";
         // end hiding -->
         </script>
-        """ % ( self.OutputString(attrs), )
+        """ % ( self.OutputString(attrs).replace('"',r'\"'), )
     # end js_output()
 
     def OutputString(self, attrs=None):
index e7c0cf1cccb09bdd1e341d1a3d97afb18ad5ffae..1cd538ce40d4a5f1d90662d07f3c55a7697bd057 100644 (file)
@@ -51,17 +51,17 @@ class CookieTests(unittest.TestCase):
 
         self.assertEqual(C.output(['path']),
             'Set-Cookie: Customer="WILE_E_COYOTE"; Path=/acme')
-        self.assertEqual(C.js_output(), """
+        self.assertEqual(C.js_output(), r"""
         <script type="text/javascript">
         <!-- begin hiding
-        document.cookie = "Customer="WILE_E_COYOTE"; Path=/acme; Version=1";
+        document.cookie = "Customer=\"WILE_E_COYOTE\"; Path=/acme; Version=1";
         // end hiding -->
         </script>
         """)
-        self.assertEqual(C.js_output(['path']), """
+        self.assertEqual(C.js_output(['path']), r"""
         <script type="text/javascript">
         <!-- begin hiding
-        document.cookie = "Customer="WILE_E_COYOTE"; Path=/acme";
+        document.cookie = "Customer=\"WILE_E_COYOTE\"; Path=/acme";
         // end hiding -->
         </script>
         """)