mirror of
https://codeberg.org/polarisfm/youtube-dl
synced 2024-11-22 08:34:32 +01:00
handle different syntax for boolean values in js_to_json
This commit is contained in:
parent
48c5663c5f
commit
1baea2d4f3
@ -1000,6 +1000,12 @@ class TestUtil(unittest.TestCase):
|
||||
on = js_to_json('{ "040": "040" }')
|
||||
self.assertEqual(json.loads(on), {'040': '040'})
|
||||
|
||||
on = js_to_json('{ "defaultQuality":!0}')
|
||||
self.assertEqual(json.loads(on), {'defaultQuality': 'true'})
|
||||
|
||||
on = js_to_json('{ "onFullscreen":!1}')
|
||||
self.assertEqual(json.loads(on), {'onFullscreen': 'false'})
|
||||
|
||||
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')
|
||||
|
@ -4081,6 +4081,11 @@ def js_to_json(code):
|
||||
elif v.startswith('/*') or v.startswith('//') or v == ',':
|
||||
return ""
|
||||
|
||||
if v == "!0":
|
||||
v = 'true'
|
||||
if v == "!1":
|
||||
v = 'false'
|
||||
|
||||
if v[0] in ("'", '"'):
|
||||
v = re.sub(r'(?s)\\.|"', lambda m: {
|
||||
'"': '\\"',
|
||||
@ -4103,7 +4108,8 @@ def js_to_json(code):
|
||||
{comment}|,(?={skip}[\]}}])|
|
||||
(?:(?<![0-9])[eE]|[a-df-zA-DF-Z_])[.a-zA-Z_0-9]*|
|
||||
\b(?:0[xX][0-9a-fA-F]+|0+[0-7]+)(?:{skip}:)?|
|
||||
[0-9]+(?={skip}:)
|
||||
[0-9]+(?={skip}:)|
|
||||
\![0-1]
|
||||
'''.format(comment=COMMENT_RE, skip=SKIP_RE), fix_kv, code)
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user