diff options
author | pukkandan <pukkandan.ytdlp@gmail.com> | 2021-11-03 16:25:48 +0530 |
---|---|---|
committer | pukkandan <pukkandan.ytdlp@gmail.com> | 2021-11-03 16:35:08 +0530 |
commit | a1fc7ca0743c8df06416e68ee74b64e07dfe7135 (patch) | |
tree | 785213545fa8858d2fd3efc6f6d8e90980fbdf14 /yt_dlp/jsinterp.py | |
parent | c588b602d34f005dc018ae004281226741414192 (diff) | |
download | hypervideo-pre-a1fc7ca0743c8df06416e68ee74b64e07dfe7135.tar.lz hypervideo-pre-a1fc7ca0743c8df06416e68ee74b64e07dfe7135.tar.xz hypervideo-pre-a1fc7ca0743c8df06416e68ee74b64e07dfe7135.zip |
[jsinterp] Handle default in switch better
Diffstat (limited to 'yt_dlp/jsinterp.py')
-rw-r--r-- | yt_dlp/jsinterp.py | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/yt_dlp/jsinterp.py b/yt_dlp/jsinterp.py index 5c79a8110..bb2a0ae0b 100644 --- a/yt_dlp/jsinterp.py +++ b/yt_dlp/jsinterp.py @@ -228,21 +228,25 @@ class JSInterpreter(object): switch_val, remaining = self._seperate_at_paren(expr[m.end() - 1:], ')') switch_val = self.interpret_expression(switch_val, local_vars, allow_recursion) body, expr = self._seperate_at_paren(remaining, '}') - body, default = body.split('default:') if 'default:' in body else (body, None) - items = body.split('case ')[1:] - if default: - items.append(f'default:{default}') - matched = False - for item in items: - case, stmt = [i.strip() for i in self._seperate(item, ':', 1)] - matched = matched or case == 'default' or switch_val == self.interpret_expression(case, local_vars, allow_recursion) - if matched: + items = body.replace('default:', 'case default:').split('case ')[1:] + for default in (False, True): + matched = False + for item in items: + case, stmt = [i.strip() for i in self._seperate(item, ':', 1)] + if default: + matched = matched or case == 'default' + elif not matched: + matched = case != 'default' and switch_val == self.interpret_expression(case, local_vars, allow_recursion) + if not matched: + continue try: ret, should_abort = self.interpret_statement(stmt, local_vars, allow_recursion - 1) if should_abort: return ret except JS_Break: break + if matched: + break return self.interpret_statement(expr, local_vars, allow_recursion - 1)[0] # Comma seperated statements |