luci-base: cbi.js: fix unintended number sign overflow in format
Fixes: #3003 Signed-off-by: Jo-Philipp Wich <jo@mein.io>
This commit is contained in:
parent
642b8277df
commit
6d9a23af60
1 changed files with 7 additions and 6 deletions
|
@ -566,7 +566,7 @@ String.prototype.format = function()
|
||||||
|
|
||||||
switch(pType) {
|
switch(pType) {
|
||||||
case 'b':
|
case 'b':
|
||||||
subst = (~~param || 0).toString(2);
|
subst = Math.floor(+param || 0).toString(2);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'c':
|
case 'c':
|
||||||
|
@ -574,11 +574,12 @@ String.prototype.format = function()
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'd':
|
case 'd':
|
||||||
subst = (~~param || 0);
|
subst = Math.floor(+param || 0).toFixed(0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'u':
|
case 'u':
|
||||||
subst = ~~Math.abs(+param || 0);
|
var n = +param || 0;
|
||||||
|
subst = Math.floor((n < 0) ? 0x100000000 + n : n).toFixed(0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'f':
|
case 'f':
|
||||||
|
@ -588,7 +589,7 @@ String.prototype.format = function()
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'o':
|
case 'o':
|
||||||
subst = (~~param || 0).toString(8);
|
subst = Math.floor(+param || 0).toString(8);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 's':
|
case 's':
|
||||||
|
@ -596,11 +597,11 @@ String.prototype.format = function()
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'x':
|
case 'x':
|
||||||
subst = ('' + (~~param || 0).toString(16)).toLowerCase();
|
subst = Math.floor(+param || 0).toString(16).toLowerCase();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'X':
|
case 'X':
|
||||||
subst = ('' + (~~param || 0).toString(16)).toUpperCase();
|
subst = Math.floor(+param || 0).toString(16).toUpperCase();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'h':
|
case 'h':
|
||||||
|
|
Loading…
Reference in a new issue