mirror of
https://github.com/yt-dlp/yt-dlp.git
synced 2024-12-02 19:36:45 +00:00
[jsinterp] Fix escape in regex
This commit is contained in:
parent
b505e8517a
commit
05deb747bb
|
@ -352,6 +352,11 @@ def test_regex(self):
|
||||||
''')
|
''')
|
||||||
self.assertEqual(jsi.call_function('x').flags & re.I, re.I)
|
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):
|
def test_char_code_at(self):
|
||||||
jsi = JSInterpreter('function x(i){return "test".charCodeAt(i)}')
|
jsi = JSInterpreter('function x(i){return "test".charCodeAt(i)}')
|
||||||
self.assertEqual(jsi.call_function('x', 0), 116)
|
self.assertEqual(jsi.call_function('x', 0), 116)
|
||||||
|
|
|
@ -122,6 +122,10 @@
|
||||||
'https://www.youtube.com/s/player/113ca41c/player_ias.vflset/en_US/base.js',
|
'https://www.youtube.com/s/player/113ca41c/player_ias.vflset/en_US/base.js',
|
||||||
'cgYl-tlYkhjT7A', 'hI7BBr2zUgcmMg',
|
'cgYl-tlYkhjT7A', 'hI7BBr2zUgcmMg',
|
||||||
),
|
),
|
||||||
|
(
|
||||||
|
'https://www.youtube.com/s/player/c57c113c/player_ias.vflset/en_US/base.js',
|
||||||
|
'M92UUMHa8PdvPd3wyM', '3hPqLJsiNZx7yA',
|
||||||
|
),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -2702,7 +2702,7 @@ def _extract_n_function_name(self, jscode):
|
||||||
|
|
||||||
def _extract_n_function_code(self, video_id, player_url):
|
def _extract_n_function_code(self, video_id, player_url):
|
||||||
player_id = self._extract_player_info(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)
|
jscode = func_code or self._load_player(video_id, player_url)
|
||||||
jsi = JSInterpreter(jscode)
|
jsi = JSInterpreter(jscode)
|
||||||
|
|
||||||
|
|
|
@ -245,11 +245,12 @@ def _separate(expr, delim=',', max_split=None):
|
||||||
counters[_MATCHING_PARENS[char]] += 1
|
counters[_MATCHING_PARENS[char]] += 1
|
||||||
elif not in_quote and char in counters:
|
elif not in_quote and char in counters:
|
||||||
counters[char] -= 1
|
counters[char] -= 1
|
||||||
elif not escaping and char in _QUOTES and in_quote in (char, None):
|
elif not escaping:
|
||||||
if in_quote or after_op or char != '/':
|
if char in _QUOTES and in_quote in (char, None):
|
||||||
in_quote = None if in_quote and not in_regex_char_group else char
|
if in_quote or after_op or char != '/':
|
||||||
elif in_quote == '/' and char in '[]':
|
in_quote = None if in_quote and not in_regex_char_group else char
|
||||||
in_regex_char_group = char == '['
|
elif in_quote == '/' and char in '[]':
|
||||||
|
in_regex_char_group = char == '['
|
||||||
escaping = not escaping and in_quote and 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)
|
after_op = not in_quote and char in OP_CHARS or (char.isspace() and after_op)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue