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

index 03d1627de9ca13837501eb24cb4b1c17d336a973..695161a380f857ff8ab7096f4c1fa584b6472e92 100644 (file)
@@ -392,7 +392,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 01017e15c04f8abf6e10e4de1c0d25dd2a9128d6..158dd634b0b13b47f6eb3cdc00d577d286184cb0 100644 (file)
@@ -50,17 +50,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>
         """)