From 4d4c7e1c6930861f8388ce3cdd7a5335bf860e7d Mon Sep 17 00:00:00 2001 From: doe1080 <98906116+doe1080@users.noreply.github.com> Date: Sun, 4 Jan 2026 05:53:16 +0900 Subject: [PATCH] [utils] `js_to_json`: Prevent false positives for octals (#15474) Authored by: doe1080 --- test/test_utils.py | 3 +++ yt_dlp/utils/_utils.py | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/test/test_utils.py b/test/test_utils.py index ce865511c6..0ee5c58fa8 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -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') diff --git a/yt_dlp/utils/_utils.py b/yt_dlp/utils/_utils.py index 2ec697b100..695be84316 100644 --- a/yt_dlp/utils/_utils.py +++ b/yt_dlp/utils/_utils.py @@ -2830,7 +2830,7 @@ def js_to_json(code, vars={}, *, strict=False): {STRING_RE}| {COMMENT_RE}|,(?={SKIP_RE}[\]}}])| void\s0|(?:(?