mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2026-02-18 14:35:51 +00:00
[jsinterp] Stringify bracket notation keys in object access (#15989)
Authored by: bashonly
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user