From 4ca8c44a073d5aa3a3e3112c35b2b23d6ce25ac6 Mon Sep 17 00:00:00 2001 From: sepro Date: Sun, 9 Feb 2025 22:37:23 +0100 Subject: [PATCH] [jsinterp] Improve zeroise (#12313) Authored by: seproDev --- test/test_jsinterp.py | 10 ++++++++++ test/test_youtube_signature.py | 4 ++++ yt_dlp/jsinterp.py | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/test/test_jsinterp.py b/test/test_jsinterp.py index c1464f2cd..ed3ca61c4 100644 --- a/test/test_jsinterp.py +++ b/test/test_jsinterp.py @@ -93,6 +93,16 @@ class TestJSInterpreter(unittest.TestCase): self._test('function f(){return 0 ?? 42;}', 0) self._test('function f(){return "life, the universe and everything" < 42;}', False) self._test('function f(){return 0 - 7 * - 6;}', 42) + self._test('function f(){return true << "5";}', 32) + self._test('function f(){return true << true;}', 2) + self._test('function f(){return "19" & "21.9";}', 17) + self._test('function f(){return "19" & false;}', 0) + self._test('function f(){return "11.0" >> "2.1";}', 2) + self._test('function f(){return 5 ^ 9;}', 12) + self._test('function f(){return 0.0 << NaN}', 0) + self._test('function f(){return null << undefined}', 0) + # TODO: Does not work due to number too large + # self._test('function f(){return 21 << 4294967297}', 42) def test_array_access(self): self._test('function f(){var x = [1,2,3]; x[0] = 4; x[0] = 5; x[2.0] = 7; return x;}', [5, 2, 7]) diff --git a/test/test_youtube_signature.py b/test/test_youtube_signature.py index 13436f088..7ae627f2c 100644 --- a/test/test_youtube_signature.py +++ b/test/test_youtube_signature.py @@ -201,6 +201,10 @@ _NSIG_TESTS = [ 'https://www.youtube.com/s/player/2f1832d2/player_ias.vflset/en_US/base.js', 'YWt1qdbe8SAfkoPHW5d', 'RrRjWQOJmBiP', ), + ( + 'https://www.youtube.com/s/player/9c6dfc4a/player_ias.vflset/en_US/base.js', + 'jbu7ylIosQHyJyJV', 'uwI0ESiynAmhNg', + ), ] diff --git a/yt_dlp/jsinterp.py b/yt_dlp/jsinterp.py index bd6a47004..ac0629715 100644 --- a/yt_dlp/jsinterp.py +++ b/yt_dlp/jsinterp.py @@ -25,7 +25,7 @@ def _js_bit_op(op): with contextlib.suppress(TypeError): if math.isnan(x): # NB: NaN cannot be checked by membership return 0 - return x + return int(float(x)) def wrapped(a, b): return op(zeroise(a), zeroise(b)) & 0xffffffff