From a4392af113b5a439ff33601fdef900c1e802c139 Mon Sep 17 00:00:00 2001 From: bashonly Date: Wed, 26 Mar 2025 23:36:37 -0500 Subject: [PATCH] [jsinterp] `interpret_statement`: Match `attribute` before `indexing` Authored by: bashonly --- test/test_jsinterp.py | 3 +++ yt_dlp/jsinterp.py | 10 ++++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/test/test_jsinterp.py b/test/test_jsinterp.py index 17184d5b0d..7b01bc39cd 100644 --- a/test/test_jsinterp.py +++ b/test/test_jsinterp.py @@ -443,6 +443,9 @@ class TestJSInterpreter(unittest.TestCase): self._test('function f(){return "012345678".slice(-1, 1)}', '') self._test('function f(){return "012345678".slice(-3, -1)}', '67') + def test_splice(self): + self._test('function f(){var T = ["0", "1", "2"]; T["splice"](2, 1, "0")[0]; return T }', ['0', '1', '0']) + def test_js_number_to_string(self): for test, radix, expected in [ (0, None, '0'), diff --git a/yt_dlp/jsinterp.py b/yt_dlp/jsinterp.py index c69d099350..f2f98135be 100644 --- a/yt_dlp/jsinterp.py +++ b/yt_dlp/jsinterp.py @@ -611,10 +611,16 @@ class JSInterpreter: =(?!=)(?P.*)$ )|(?P (?!if|return|true|false|null|undefined|NaN)(?P{_NAME_RE})$ + )|(?P + (?P{_NAME_RE})(?: + (?P\?)?\.(?P[^(]+)| + \[(?P[^[\]]+ + (?:\[[^[\]]+ + (?:\[[^\]]+\])?\] + )?) + \])\s* )|(?P (?P{_NAME_RE})\[(?P.+)\]$ - )|(?P - (?P{_NAME_RE})(?:(?P\?)?\.(?P[^(]+)|\[(?P[^\[\]]+(?:\[[^\[\]]+(?:\[[^\]]+\])?\])?)\])\s* )|(?P (?P{_NAME_RE})\((?P.*)\)$ )''', expr)