From d305dd73a3d6927f0a2c63d08662a183fa173833 Mon Sep 17 00:00:00 2001 From: Philipp Hagemeister Date: Wed, 18 Feb 2015 23:59:50 +0100 Subject: [PATCH] [utils] Fix js_to_json Previously, the runtime could be atrocious for longer inputs. --- test/test_utils.py | 4 ++++ youtube_dl/utils.py | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/test/test_utils.py b/test/test_utils.py index 1c29d0889..c7373af1e 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -370,6 +370,10 @@ def test_js_to_json_realworld(self): "playlist":[{"controls":{"all":null}}] }''') + 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)) + def test_js_to_json_edgecases(self): on = js_to_json("{abc_def:'1\\'\\\\2\\\\\\'3\"4'}") self.assertEqual(json.loads(on), {"abc_def": "1'\\2\\'3\"4"}) diff --git a/youtube_dl/utils.py b/youtube_dl/utils.py index 3eb6bc6d4..4358137a0 100644 --- a/youtube_dl/utils.py +++ b/youtube_dl/utils.py @@ -1560,8 +1560,8 @@ def fix_kv(m): return '"%s"' % v res = re.sub(r'''(?x) - "(?:[^"\\]*(?:\\\\|\\")?)*"| - '(?:[^'\\]*(?:\\\\|\\')?)*'| + "(?:[^"\\]*(?:\\\\|\\['"nu]))*[^"\\]*"| + '(?:[^'\\]*(?:\\\\|\\['"nu]))*[^'\\]*'| [a-zA-Z_][.a-zA-Z_0-9]* ''', fix_kv, code) res = re.sub(r',(\s*\])', lambda m: m.group(1), res)