aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordirkf <fieldhouse@gmx.net>2024-07-10 18:02:11 +0100
committerdirkf <fieldhouse@gmx.net>2024-07-11 00:50:46 +0100
commit76ac69917ec76ba663da843795f46916831e6da9 (patch)
tree896349f7b095a66dd6ba58a3a8321062d4f39e90
parent756f6b45c7c9a77f0fa912f882afe7e04878a01b (diff)
[jsinterp] Further improve expression parsing (fix fd8242e)
Passes tests from yt-dlp
-rw-r--r--youtube_dl/jsinterp.py9
1 files changed, 6 insertions, 3 deletions
diff --git a/youtube_dl/jsinterp.py b/youtube_dl/jsinterp.py
index 799497acb..a2074a91e 100644
--- a/youtube_dl/jsinterp.py
+++ b/youtube_dl/jsinterp.py
@@ -804,16 +804,19 @@ class JSInterpreter(object):
if op in ('+', '-'):
# simplify/adjust consecutive instances of these operators
undone = 0
- while len(separated) > 1 and not separated[-1].strip():
+ separated = [s.strip() for s in separated]
+ while len(separated) > 1 and not separated[-1]:
undone += 1
separated.pop()
if op == '-' and undone % 2 != 0:
right_expr = op + right_expr
elif op == '+':
- while len(separated) > 1 and separated[-1].strip() in self.OP_CHARS:
+ while len(separated) > 1 and set(separated[-1]) <= self.OP_CHARS:
+ right_expr = separated.pop() + right_expr
+ if separated[-1][-1:] in self.OP_CHARS:
right_expr = separated.pop() + right_expr
# hanging op at end of left => unary + (strip) or - (push right)
- left_val = separated[-1]
+ left_val = separated[-1] if separated else ''
for dm_op in ('*', '%', '/', '**'):
bodmas = tuple(self._separate(left_val, dm_op, skip_delims=skip_delim))
if len(bodmas) > 1 and not bodmas[-1].strip():