aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/test_utils.py1
-rw-r--r--yt_dlp/utils/_utils.py3
2 files changed, 3 insertions, 1 deletions
diff --git a/test/test_utils.py b/test/test_utils.py
index 42dc7f937..e60ceed8f 100644
--- a/test/test_utils.py
+++ b/test/test_utils.py
@@ -1260,6 +1260,7 @@ class TestUtil(unittest.TestCase):
def test_js_to_json_malformed(self):
self.assertEqual(js_to_json('42a1'), '42"a1"')
self.assertEqual(js_to_json('42a-1'), '42"a"-1')
+ self.assertEqual(js_to_json('{a: `${e("")}`}'), '{"a": "\\"e\\"(\\"\\")"}')
def test_js_to_json_template_literal(self):
self.assertEqual(js_to_json('`Hello ${name}`', {'name': '"world"'}), '"Hello world"')
diff --git a/yt_dlp/utils/_utils.py b/yt_dlp/utils/_utils.py
index 0140acaa3..24525560e 100644
--- a/yt_dlp/utils/_utils.py
+++ b/yt_dlp/utils/_utils.py
@@ -2767,7 +2767,8 @@ def js_to_json(code, vars={}, *, strict=False):
def template_substitute(match):
evaluated = js_to_json(match.group(1), vars, strict=strict)
if evaluated[0] == '"':
- return json.loads(evaluated)
+ with contextlib.suppress(json.JSONDecodeError):
+ return json.loads(evaluated)
return evaluated
def fix_kv(m):