mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2025-05-16 17:05:41 -05:00
[utils] js_to_json
: Make function less fatal (#12715)
Authored by: seproDev
This commit is contained in:
parent
b7fbb5a0a1
commit
9491b44032
2 changed files with 3 additions and 1 deletions
|
@ -1260,6 +1260,7 @@ def test_js_to_json_edgecases(self):
|
||||||
def test_js_to_json_malformed(self):
|
def test_js_to_json_malformed(self):
|
||||||
self.assertEqual(js_to_json('42a1'), '42"a1"')
|
self.assertEqual(js_to_json('42a1'), '42"a1"')
|
||||||
self.assertEqual(js_to_json('42a-1'), '42"a"-1')
|
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):
|
def test_js_to_json_template_literal(self):
|
||||||
self.assertEqual(js_to_json('`Hello ${name}`', {'name': '"world"'}), '"Hello world"')
|
self.assertEqual(js_to_json('`Hello ${name}`', {'name': '"world"'}), '"Hello world"')
|
||||||
|
|
|
@ -2767,7 +2767,8 @@ def process_escape(match):
|
||||||
def template_substitute(match):
|
def template_substitute(match):
|
||||||
evaluated = js_to_json(match.group(1), vars, strict=strict)
|
evaluated = js_to_json(match.group(1), vars, strict=strict)
|
||||||
if evaluated[0] == '"':
|
if evaluated[0] == '"':
|
||||||
return json.loads(evaluated)
|
with contextlib.suppress(json.JSONDecodeError):
|
||||||
|
return json.loads(evaluated)
|
||||||
return evaluated
|
return evaluated
|
||||||
|
|
||||||
def fix_kv(m):
|
def fix_kv(m):
|
||||||
|
|
Loading…
Reference in a new issue