From 420d53387cff54ea1fccca061438d59bdb50a39c Mon Sep 17 00:00:00 2001 From: dirkf Date: Mon, 10 Mar 2025 11:44:06 +0000 Subject: [JSInterp] Improve tests * from yt-dlp/yt-dlp#12313 * also fix d7c2708 --- youtube_dl/jsinterp.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'youtube_dl/jsinterp.py') diff --git a/youtube_dl/jsinterp.py b/youtube_dl/jsinterp.py index 5a45fbb03..d9b33fa44 100644 --- a/youtube_dl/jsinterp.py +++ b/youtube_dl/jsinterp.py @@ -154,6 +154,7 @@ def _js_to_primitive(v): ) +# more exact: yt-dlp/yt-dlp#12110 def _js_toString(v): return ( 'undefined' if v is JS_Undefined @@ -162,7 +163,7 @@ def _js_toString(v): else 'null' if v is None # bool <= int: do this first else ('false', 'true')[v] if isinstance(v, bool) - else '{0:.7f}'.format(v).rstrip('.0') if isinstance(v, compat_numeric_types) + else re.sub(r'(?<=\d)\.?0*$', '', '{0:.7f}'.format(v)) if isinstance(v, compat_numeric_types) else _js_to_primitive(v)) -- cgit v1.2.3