From 05deb747bb18febb803b47119ca7bc432ffb80c8 Mon Sep 17 00:00:00 2001 From: pukkandan Date: Thu, 1 Sep 2022 13:14:04 +0530 Subject: [PATCH] [jsinterp] Fix escape in regex --- test/test_jsinterp.py | 5 +++++ test/test_youtube_signature.py | 4 ++++ yt_dlp/extractor/youtube.py | 2 +- yt_dlp/jsinterp.py | 11 ++++++----- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/test/test_jsinterp.py b/test/test_jsinterp.py index 4b6e22bac..0cdf726fb 100644 --- a/test/test_jsinterp.py +++ b/test/test_jsinterp.py @@ -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) diff --git a/test/test_youtube_signature.py b/test/test_youtube_signature.py index 717c94954..b1c5cb2b3 100644 --- a/test/test_youtube_signature.py +++ b/test/test_youtube_signature.py @@ -122,6 +122,10 @@ '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', + ), ] diff --git a/yt_dlp/extractor/youtube.py b/yt_dlp/extractor/youtube.py index 9303557f7..2748b5dc5 100644 --- a/yt_dlp/extractor/youtube.py +++ b/yt_dlp/extractor/youtube.py @@ -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) diff --git a/yt_dlp/jsinterp.py b/yt_dlp/jsinterp.py index 51c7beed4..27d7f0dfa 100644 --- a/yt_dlp/jsinterp.py +++ b/yt_dlp/jsinterp.py @@ -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)