From c9c86519753d6cdafa052945d2de0d3fcd448927 Mon Sep 17 00:00:00 2001 From: bashonly <88596187+bashonly@users.noreply.github.com> Date: Tue, 17 Feb 2026 17:20:54 -0600 Subject: [PATCH] [jsinterp] Stringify bracket notation keys in object access (#15989) Authored by: bashonly --- test/test_jsinterp.py | 1 + yt_dlp/jsinterp.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_jsinterp.py b/test/test_jsinterp.py index 4da8ae3536..df273b41f0 100644 --- a/test/test_jsinterp.py +++ b/test/test_jsinterp.py @@ -330,6 +330,7 @@ class TestJSInterpreter(unittest.TestCase): self._test('function f() { let a = {m1: 42, m2: 0 }; return [a["m1"], a.m2]; }', [42, 0]) self._test('function f() { let a; return a?.qq; }', JS_Undefined) self._test('function f() { let a = {m1: 42, m2: 0 }; return a?.qq; }', JS_Undefined) + self._test('function f() { let a = {"1": 123}; return a[1]; }', 123) def test_regex(self): self._test('function f() { let a=/,,[/,913,/](,)}/; }', None) diff --git a/yt_dlp/jsinterp.py b/yt_dlp/jsinterp.py index 6ca2b16375..362e5a4380 100644 --- a/yt_dlp/jsinterp.py +++ b/yt_dlp/jsinterp.py @@ -385,7 +385,7 @@ class JSInterpreter: if idx == 'length': return len(obj) try: - return obj[int(idx)] if isinstance(obj, list) else obj[idx] + return obj[int(idx)] if isinstance(obj, list) else obj[str(idx)] except Exception as e: if allow_undefined: return JS_Undefined