]> jfr.im git - yt-dlp.git/commitdiff
Update to ytdl-commit-07af47
authorpukkandan <redacted>
Wed, 21 Jun 2023 03:21:14 +0000 (08:51 +0530)
committerpukkandan <redacted>
Wed, 21 Jun 2023 03:51:23 +0000 (09:21 +0530)
[YouTube] Improve fix for ae8ba2c
https://github.com/ytdl-org/youtube-dl/commit/07af47960f3bb262ead02490ce65c8c45c01741e

test/test_jsinterp.py
yt_dlp/casefold.py [new file with mode: 0644]
yt_dlp/jsinterp.py

index e9682ddab0703ef5e3041f9a74173a1140670217..86928a6a0200e2224462475ae6486d4eab4f5f4b 100644 (file)
@@ -35,6 +35,21 @@ def test_basic(self):
         self._test('function f(){42}', None)
         self._test('var f = function(){return 42;}', 42)
 
+    def test_add(self):
+        self._test('function f(){return 42 + 7;}', 49)
+        self._test('function f(){return 42 + undefined;}', NaN)
+        self._test('function f(){return 42 + null;}', 42)
+
+    def test_sub(self):
+        self._test('function f(){return 42 - 7;}', 35)
+        self._test('function f(){return 42 - undefined;}', NaN)
+        self._test('function f(){return 42 - null;}', 42)
+
+    def test_mul(self):
+        self._test('function f(){return 42 * 7;}', 294)
+        self._test('function f(){return 42 * undefined;}', NaN)
+        self._test('function f(){return 42 * null;}', 0)
+
     def test_div(self):
         jsi = JSInterpreter('function f(a, b){return a / b;}')
         self._test(jsi, NaN, args=(0, 0))
@@ -42,6 +57,17 @@ def test_div(self):
         self._test(jsi, float('inf'), args=(2, 0))
         self._test(jsi, 0, args=(0, 3))
 
+    def test_mod(self):
+        self._test('function f(){return 42 % 7;}', 0)
+        self._test('function f(){return 42 % 0;}', NaN)
+        self._test('function f(){return 42 % undefined;}', NaN)
+
+    def test_exp(self):
+        self._test('function f(){return 42 ** 2;}', 1764)
+        self._test('function f(){return 42 ** undefined;}', NaN)
+        self._test('function f(){return 42 ** null;}', 1)
+        self._test('function f(){return undefined ** 42;}', NaN)
+
     def test_calc(self):
         self._test('function f(a){return 2*a+1;}', 7, args=[3])
 
diff --git a/yt_dlp/casefold.py b/yt_dlp/casefold.py
new file mode 100644 (file)
index 0000000..41a53e5
--- /dev/null
@@ -0,0 +1,5 @@
+import warnings
+
+warnings.warn(DeprecationWarning(f'{__name__} is deprecated'))
+
+casefold = str.casefold
index 9c280fb86f839d2ce72efece3167d1e2e306e8f7..bda3fb45991e6a06683bddf38676629a154141d0 100644 (file)
@@ -812,9 +812,9 @@ def extract_function_code(self, funcname):
                 \((?P<args>[^)]*)\)\s*
                 (?P<code>{.+})''' % {'name': re.escape(funcname)},
             self.code)
-        code, _ = self._separate_at_paren(func_m.group('code'))
         if func_m is None:
             raise self.Exception(f'Could not find JS function "{funcname}"')
+        code, _ = self._separate_at_paren(func_m.group('code'))
         return [x.strip() for x in func_m.group('args').split(',')], code
 
     def extract_function(self, funcname):