mirror of
				https://github.com/yt-dlp/yt-dlp.git
				synced 2025-10-31 14:45:14 +00:00 
			
		
		
		
	[jsinterp] Fix division (#7279)
* Fixes nsig decryption for Youtube JS player `8c7583ff` Authored by: bashonly
This commit is contained in:
		| @@ -28,6 +28,13 @@ class TestJSInterpreter(unittest.TestCase): | |||||||
|     def test_calc(self): |     def test_calc(self): | ||||||
|         self._test('function f(a){return 2*a+1;}', 7, args=[3]) |         self._test('function f(a){return 2*a+1;}', 7, args=[3]) | ||||||
| 
 | 
 | ||||||
|  |     def test_div(self): | ||||||
|  |         jsi = JSInterpreter('function f(a, b){return a / b;}') | ||||||
|  |         self.assertTrue(math.isnan(jsi.call_function('f', 0, 0))) | ||||||
|  |         self.assertTrue(math.isnan(jsi.call_function('f', JS_Undefined, 1))) | ||||||
|  |         self.assertTrue(math.isinf(jsi.call_function('f', 2, 0))) | ||||||
|  |         self.assertEqual(jsi.call_function('f', 0, 3), 0) | ||||||
|  | 
 | ||||||
|     def test_empty_return(self): |     def test_empty_return(self): | ||||||
|         self._test('function f(){return; y()}', None) |         self._test('function f(){return; y()}', None) | ||||||
| 
 | 
 | ||||||
|   | |||||||
| @@ -150,6 +150,10 @@ _NSIG_TESTS = [ | |||||||
|         'https://www.youtube.com/s/player/cfa9e7cb/player_ias.vflset/en_US/base.js', |         'https://www.youtube.com/s/player/cfa9e7cb/player_ias.vflset/en_US/base.js', | ||||||
|         'aCi3iElgd2kq0bxVbQ', 'QX1y8jGb2IbZ0w', |         'aCi3iElgd2kq0bxVbQ', 'QX1y8jGb2IbZ0w', | ||||||
|     ), |     ), | ||||||
|  |     ( | ||||||
|  |         'https://www.youtube.com/s/player/8c7583ff/player_ias.vflset/en_US/base.js', | ||||||
|  |         '1wWCVpRR96eAmMI87L', 'KSkWAVv1ZQxC3A', | ||||||
|  |     ), | ||||||
| ] | ] | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|   | |||||||
| @@ -44,7 +44,7 @@ def _js_arith_op(op): | |||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def _js_div(a, b): | def _js_div(a, b): | ||||||
|     if JS_Undefined in (a, b) or not (a and b): |     if JS_Undefined in (a, b) or not (a or b): | ||||||
|         return float('nan') |         return float('nan') | ||||||
|     return (a or 0) / b if b else float('inf') |     return (a or 0) / b if b else float('inf') | ||||||
| 
 | 
 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 bashonly
					bashonly