From: Jo-Philipp Wich Date: Thu, 6 Jun 2019 19:06:25 +0000 (+0200) Subject: luci-base: cbi.js: fix number rounding in string.format() X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=0bcb9f9f1d5f30a0a06584ddf4956d754c705c9d;p=oweals%2Fluci.git luci-base: cbi.js: fix number rounding in string.format() Ensure that patterns like %d, %x, %o or %b properly truncate their operands to whole integers. Signed-off-by: Jo-Philipp Wich --- diff --git a/modules/luci-base/htdocs/luci-static/resources/cbi.js b/modules/luci-base/htdocs/luci-static/resources/cbi.js index 701de0386..d4d61eb38 100644 --- a/modules/luci-base/htdocs/luci-static/resources/cbi.js +++ b/modules/luci-base/htdocs/luci-static/resources/cbi.js @@ -566,7 +566,7 @@ String.prototype.format = function() switch(pType) { case 'b': - subst = (+param || 0).toString(2); + subst = (~~param || 0).toString(2); break; case 'c': @@ -574,7 +574,7 @@ String.prototype.format = function() break; case 'd': - subst = ~~(+param || 0); + subst = (~~param || 0); break; case 'u': @@ -588,7 +588,7 @@ String.prototype.format = function() break; case 'o': - subst = (+param || 0).toString(8); + subst = (~~param || 0).toString(8); break; case 's': @@ -596,11 +596,11 @@ String.prototype.format = function() break; case 'x': - subst = ('' + (+param || 0).toString(16)).toLowerCase(); + subst = ('' + (~~param || 0).toString(16)).toLowerCase(); break; case 'X': - subst = ('' + (+param || 0).toString(16)).toUpperCase(); + subst = ('' + (~~param || 0).toString(16)).toUpperCase(); break; case 'h':