Browse Source

[utils:js_to_json] Fix bad escape in double quoted strings

totalwebcasting
Sergey M․ 9 years ago
parent
commit
d01949dc89
2 changed files with 5 additions and 2 deletions
  1. +3
    -0
      test/test_utils.py
  2. +2
    -2
      youtube_dl/utils.py

+ 3
- 0
test/test_utils.py View 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))


+ 2
- 2
youtube_dl/utils.py View 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: {
'\\\\': '\\\\',


Loading…
Cancel
Save