]> jfr.im git - yt-dlp.git/commitdiff
[jsinterp] Fix escape in regex
authorpukkandan <redacted>
Thu, 1 Sep 2022 07:44:04 +0000 (13:14 +0530)
committerpukkandan <redacted>
Thu, 1 Sep 2022 11:16:32 +0000 (16:46 +0530)
test/test_jsinterp.py
test/test_youtube_signature.py
yt_dlp/extractor/youtube.py
yt_dlp/jsinterp.py

index 4b6e22bac27251f3d0291f168db6b244ee3bfec9..0cdf726fbe48c4450c318b9fd4110e6a19ddddb0 100644 (file)
@@ -352,6 +352,11 @@ def test_regex(self):
         ''')
         self.assertEqual(jsi.call_function('x').flags & re.I, re.I)
 
+        jsi = JSInterpreter('''
+        function x() { let a=/,][}",],()}(\[)/; return a; }
+        ''')
+        self.assertEqual(jsi.call_function('x').pattern, r',][}",],()}(\[)')
+
     def test_char_code_at(self):
         jsi = JSInterpreter('function x(i){return "test".charCodeAt(i)}')
         self.assertEqual(jsi.call_function('x', 0), 116)
index 717c949540b73d1e830cc32e49b515dcb36ea4d1..b1c5cb2b3519b0ef1bd3294e689ea689cb39d6d4 100644 (file)
         'https://www.youtube.com/s/player/113ca41c/player_ias.vflset/en_US/base.js',
         'cgYl-tlYkhjT7A', 'hI7BBr2zUgcmMg',
     ),
+    (
+        'https://www.youtube.com/s/player/c57c113c/player_ias.vflset/en_US/base.js',
+        'M92UUMHa8PdvPd3wyM', '3hPqLJsiNZx7yA',
+    ),
 ]
 
 
index 9303557f76b760fa67a3ddb6bb594e1e0a755e68..2748b5dc52a866135f8f435adf881badfe5ecf06 100644 (file)
@@ -2702,7 +2702,7 @@ def _extract_n_function_name(self, jscode):
 
     def _extract_n_function_code(self, video_id, player_url):
         player_id = self._extract_player_info(player_url)
-        func_code = self.cache.load('youtube-nsig', player_id, min_ver='2022.08.19.2')
+        func_code = self.cache.load('youtube-nsig', player_id, min_ver='2022.09.1')
         jscode = func_code or self._load_player(video_id, player_url)
         jsi = JSInterpreter(jscode)
 
index 51c7beed433320bb2e8c6127bf9370693da582da..27d7f0dfa6289241c2cf3f542557b75e421c7f5f 100644 (file)
@@ -245,11 +245,12 @@ def _separate(expr, delim=',', max_split=None):
                 counters[_MATCHING_PARENS[char]] += 1
             elif not in_quote and char in counters:
                 counters[char] -= 1
-            elif not escaping and char in _QUOTES and in_quote in (char, None):
-                if in_quote or after_op or char != '/':
-                    in_quote = None if in_quote and not in_regex_char_group else char
-            elif in_quote == '/' and char in '[]':
-                in_regex_char_group = char == '['
+            elif not escaping:
+                if char in _QUOTES and in_quote in (char, None):
+                    if in_quote or after_op or char != '/':
+                        in_quote = None if in_quote and not in_regex_char_group else char
+                elif in_quote == '/' and char in '[]':
+                    in_regex_char_group = char == '['
             escaping = not escaping and in_quote and char == '\\'
             after_op = not in_quote and char in OP_CHARS or (char.isspace() and after_op)