aboutsummaryrefslogtreecommitdiffstats
path: root/yt_dlp/jsinterp.py
diff options
context:
space:
mode:
authorpukkandan <pukkandan.ytdlp@gmail.com>2022-05-25 17:53:46 +0530
committerpukkandan <pukkandan.ytdlp@gmail.com>2022-06-12 00:08:16 +0530
commit64fa820ccf61a7aea6c2a48b1362b3a4ec270cad (patch)
treea2b5d5f8e6bcb2bbcfe8dea06bb899a1943cff2f /yt_dlp/jsinterp.py
parent56ba69e4c991e81a449882258be08d0b6b98c648 (diff)
downloadhypervideo-pre-64fa820ccf61a7aea6c2a48b1362b3a4ec270cad.tar.lz
hypervideo-pre-64fa820ccf61a7aea6c2a48b1362b3a4ec270cad.tar.xz
hypervideo-pre-64fa820ccf61a7aea6c2a48b1362b3a4ec270cad.zip
[cleanup] Misc fixes (see desc)
* [tvver] Fix bug in 6837633a4a614920b6e43ffc6b4b8590dca8c9d7 - Closes #4054 * [rumble] Fix tests - Closes #3976 * [make] Remove `cat` abuse - Closes #3989 * [make] Revert #3684 - Closes #3814 * [utils] Improve `get_elements_by_class` - Closes #3993 * [utils] Inherit `Namespace` from `types.SimpleNamespace` * [utils] Use `re.fullmatch` for matching filters * [jsinterp] Handle quotes in `_separate` * [make_readme] Allow overshooting last line Authored by: pukkandan, kwconder, MrRawes, Lesmiscore
Diffstat (limited to 'yt_dlp/jsinterp.py')
-rw-r--r--yt_dlp/jsinterp.py8
1 files changed, 7 insertions, 1 deletions
diff --git a/yt_dlp/jsinterp.py b/yt_dlp/jsinterp.py
index 70857b798..56229cd99 100644
--- a/yt_dlp/jsinterp.py
+++ b/yt_dlp/jsinterp.py
@@ -24,6 +24,7 @@ _ASSIGN_OPERATORS.append(('=', (lambda cur, right: right)))
_NAME_RE = r'[a-zA-Z_$][a-zA-Z_$0-9]*'
_MATCHING_PARENS = dict(zip('({[', ')}]'))
+_QUOTES = '\'"'
class JS_Break(ExtractorError):
@@ -69,12 +70,17 @@ class JSInterpreter:
return
counters = {k: 0 for k in _MATCHING_PARENS.values()}
start, splits, pos, delim_len = 0, 0, 0, len(delim) - 1
+ in_quote, escaping = None, False
for idx, char in enumerate(expr):
if char in _MATCHING_PARENS:
counters[_MATCHING_PARENS[char]] += 1
elif char in counters:
counters[char] -= 1
- if char != delim[pos] or any(counters.values()):
+ elif not escaping and char in _QUOTES and in_quote in (char, None):
+ in_quote = None if in_quote else char
+ escaping = not escaping and in_quote and char == '\\'
+
+ if char != delim[pos] or any(counters.values()) or in_quote:
pos = 0
continue
elif pos != delim_len: