[jsinterp] Small updates for a85a875
authordirkf <fieldhouse@gmx.net>
Fri, 19 May 2023 12:09:18 +0000 (13:09 +0100)
committerdirkf <fieldhouse@gmx.net>
Tue, 23 May 2023 15:50:25 +0000 (16:50 +0100)
* update signature tests
* clarify NaN handling

test/test_jsinterp.py
test/test_youtube_signature.py
youtube_dl/jsinterp.py

index a8f312fde133a39f0e32b5d631593d6954250232..1cc148b152926d1666f89032ac6cd2973416b0f6 100644 (file)
@@ -516,6 +516,9 @@ class TestJSInterpreter(unittest.TestCase):
         jsi = JSInterpreter('function x(){return 42 << NaN}')
         self.assertEqual(jsi.call_function('x'), 42)
 
+        jsi = JSInterpreter('function x(){return 42 << Infinity}')
+        self.assertEqual(jsi.call_function('x'), 42)
+
     def test_32066(self):
         jsi = JSInterpreter("function x(){return Math.pow(3, 5) + new Date('1970-01-01T08:01:42.000+08:00') / 1000 * -239 - -24205;}")
         self.assertEqual(jsi.call_function('x'), 70)
index decf7ee38ee6755f75451f8e02867f54d9df4f6f..d41d708a0189245e175c2ab0a8f0204349fde7b9 100644 (file)
@@ -143,6 +143,14 @@ _NSIG_TESTS = [
         'https://www.youtube.com/s/player/dac945fd/player_ias.vflset/en_US/base.js',
         'o8BkRxXhuYsBCWi6RplPdP', '3Lx32v_hmzTm6A',
     ),
+    (
+        'https://www.youtube.com/s/player/6f20102c/player_ias.vflset/en_US/base.js',
+        'lE8DhoDmKqnmJJ', 'pJTTX6XyJP2BYw',
+    ),
+    (
+        'https://www.youtube.com/s/player/cfa9e7cb/player_ias.vflset/en_US/base.js',
+        'qO0NiMtYQ7TeJnfFG2', 'k9cuJDHNS5O7kQ',
+    ),
 ]
 
 
index f837865c4c2bbbf5cb2415c07e5dd5b7a9e565f1..dc580943e34933e4d4f9e687c92f9163d6c65e06 100644 (file)
@@ -2,7 +2,6 @@ from __future__ import unicode_literals
 
 import itertools
 import json
-import math
 import operator
 import re
 
@@ -52,6 +51,10 @@ def wraps_op(op):
     return update_and_rename_wrapper
 
 
+# NB In principle NaN cannot be checked by membership.
+# Here all NaN values are actually this one, so _NaN is _NaN,
+# although _NaN != _NaN.
+
 _NaN = float('nan')
 
 
@@ -126,13 +129,8 @@ def _js_comp_op(op):
 
 def _js_ternary(cndn, if_true=True, if_false=False):
     """Simulate JS's ternary operator (cndn?if_true:if_false)"""
-    if cndn in (False, None, 0, '', JS_Undefined):
+    if cndn in (False, None, 0, '', JS_Undefined, _NaN):
         return if_false
-    try:
-        if math.isnan(cndn):  # NB: NaN cannot be checked by membership
-            return if_false
-    except TypeError:
-        pass
     return if_true