]> git.bitcoin.ninja Git - youtube-dl/commitdiff
[utils:js_to_json] Fix bad escape in double quoted strings
authorSergey M․ <dstftw@gmail.com>
Tue, 20 Oct 2015 17:09:51 +0000 (23:09 +0600)
committerSergey M․ <dstftw@gmail.com>
Tue, 20 Oct 2015 17:09:51 +0000 (23:09 +0600)
test/test_utils.py
youtube_dl/utils.py

index a5f164c493a505667dcaa5bd54c1a2394e4e32b5..918a7a9ef886611753a790b38da81dc59b318ce6 100644 (file)
@@ -495,6 +495,9 @@ class TestUtil(unittest.TestCase):
             "playlist":[{"controls":{"all":null}}]
         }''')
 
+        inp = '''"The CW\\'s \\'Crazy Ex-Girlfriend\\'"'''
+        self.assertEqual(js_to_json(inp), '''"The CW's 'Crazy Ex-Girlfriend'"''')
+
         inp = '"SAND Number: SAND 2013-7800P\\nPresenter: Tom Russo\\nHabanero Software Training - Xyce Software\\nXyce, Sandia\\u0027s"'
         json_code = js_to_json(inp)
         self.assertEqual(json.loads(json_code), json.loads(inp))
index db5b3698e748074e33752bc22266b45375a3b7c2..a61e47646712791f0b4aa1efd2606b0667cc2b0d 100644 (file)
@@ -1701,8 +1701,8 @@ def js_to_json(code):
         if v in ('true', 'false', 'null'):
             return v
         if v.startswith('"'):
-            return v
-        if v.startswith("'"):
+            v = re.sub(r"\\'", "'", v[1:-1])
+        elif v.startswith("'"):
             v = v[1:-1]
             v = re.sub(r"\\\\|\\'|\"", lambda m: {
                 '\\\\': '\\\\',