mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2026-01-08 23:23:27 +00:00
[utils] js_to_json: Prevent false positives for octals (#15474)
Authored by: doe1080
This commit is contained in:
@@ -1280,6 +1280,9 @@ class TestUtil(unittest.TestCase):
|
||||
on = js_to_json('[new Date("spam"), \'("eggs")\']')
|
||||
self.assertEqual(json.loads(on), ['spam', '("eggs")'], msg='Date regex should match a single string')
|
||||
|
||||
on = js_to_json('[0.077, 7.06, 29.064, 169.0072]')
|
||||
self.assertEqual(json.loads(on), [0.077, 7.06, 29.064, 169.0072])
|
||||
|
||||
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')
|
||||
|
||||
@@ -2830,7 +2830,7 @@ def js_to_json(code, vars={}, *, strict=False):
|
||||
{STRING_RE}|
|
||||
{COMMENT_RE}|,(?={SKIP_RE}[\]}}])|
|
||||
void\s0|(?:(?<![0-9])[eE]|[a-df-zA-DF-Z_$])[.a-zA-Z_$0-9]*|
|
||||
\b(?:0[xX][0-9a-fA-F]+|0+[0-7]+)(?:{SKIP_RE}:)?|
|
||||
\b(?:0[xX][0-9a-fA-F]+|(?<!\.)0+[0-7]+)(?:{SKIP_RE}:)?|
|
||||
[0-9]+(?={SKIP_RE}:)|
|
||||
!+
|
||||
''', fix_kv, code)
|
||||
|
||||
Reference in New Issue
Block a user