From 410f3e73ab268f74a455798ee39de5caba90caea Mon Sep 17 00:00:00 2001 From: Philipp Hagemeister Date: Tue, 30 Sep 2014 07:56:24 +0200 Subject: [PATCH] [utils] Fix js_to_json --- test/test_utils.py | 10 ++++++++++ youtube_dl/utils.py | 6 +++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/test/test_utils.py b/test/test_utils.py index 97551ce9c..113aa44b2 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -44,6 +44,7 @@ limit_length, escape_rfc3986, escape_url, + js_to_json, ) @@ -331,5 +332,14 @@ def test_escape_url(self): ) self.assertEqual(escape_url('http://vimeo.com/56015672#at=0'), 'http://vimeo.com/56015672#at=0') + def test_js_to_json(self): + inp = '''{ + 'clip':{'provider':'pseudo'} + }''' + self.assertEqual(js_to_json(inp), '''{ + "clip":{"provider":"pseudo"} + }''') + json.loads(js_to_json(inp)) + if __name__ == '__main__': unittest.main() diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index f05747097..59851a8c0 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -673,6 +673,8 @@ def __init__(self, msg, tb=None, expected=False, cause=None, video_id=None): expected = True if video_id is not None: msg = video_id + ': ' + msg + if cause: + msg += u' (caused by %r)' % cause if not expected: msg = msg + u'; please report this issue on https://yt-dl.org/bug . Be sure to call youtube-dl with the --verbose flag and include its complete output. Make sure you are using the latest version; type youtube-dl -U to update.' super(ExtractorError, self).__init__(msg) @@ -1598,7 +1600,9 @@ def fix_kv(m): ([{,]\s*) ("[^"]*"|\'[^\']*\'|[a-z0-9A-Z]+) (:\s*) - ([0-9.]+|true|false|"[^"]*"|\'[^\']*\'|\[|\{) + ([0-9.]+|true|false|"[^"]*"|\'[^\']*\'| + (?=\[|\{) + ) ''', fix_kv, code) res = re.sub(r',(\s*\])', lambda m: m.group(1), res) return res