]> jfr.im git - yt-dlp.git/blobdiff - yt_dlp/jsinterp.py
[cleanup] Misc fixes (see desc)
[yt-dlp.git] / yt_dlp / jsinterp.py
index 70857b79816812be79bc9c4d4a32deda3a8834e1..56229cd992fa313f31e0fb552ac8e4bca9a7ecb4 100644 (file)
@@ -24,6 +24,7 @@
 _NAME_RE = r'[a-zA-Z_$][a-zA-Z_$0-9]*'
 
 _MATCHING_PARENS = dict(zip('({[', ')}]'))
+_QUOTES = '\'"'
 
 
 class JS_Break(ExtractorError):
@@ -69,12 +70,17 @@ def _separate(expr, delim=',', max_split=None):
             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: