library: Lua formatNum should check that the value is not infinity or NaN

The core formatNum method only works on strings which pass `is_numeric`,
not NaN and +/- infinity.

Bug: T267587
Change-Id: Ib7706ad40f7ee2da6ab7c6b2dab6ae8d129dab52
This commit is contained in:
C. Scott Ananian 2020-11-09 16:04:41 -05:00 committed by jenkins-bot
parent f0c3975e43
commit 078253bd06
2 changed files with 36 additions and 0 deletions

View file

@ -297,6 +297,12 @@ class Scribunto_LuaLanguageLibrary extends Scribunto_LuaLibraryBase {
public function formatNum( $lang, $args ) {
$num = $args[0];
$this->checkType( 'formatNum', 1, $num, 'number' );
if ( is_infinite( $num ) ) {
throw new Scribunto_LuaError( "bad argument #1 to 'formatDate' (infinite)" );
}
if ( is_nan( $num ) ) {
throw new Scribunto_LuaError( "bad argument #1 to 'formatDate' (NaN)" );
}
$noCommafy = false;
if ( isset( $args[1] ) ) {

View file

@ -249,6 +249,36 @@ return testframework.getTestProvider( {
}
},
{ name = 'lang:formatNum (NaN)', func = test_method,
args = { 'formatNum', 0/0 },
expect = {
"bad argument #1 to 'formatDate' (NaN)",
"bad argument #1 to 'formatDate' (NaN)",
"bad argument #1 to 'formatDate' (NaN)",
"language code '[[bogus]]' is invalid",
}
},
{ name = 'lang:formatNum (Inf)', func = test_method,
args = { 'formatNum', 1/0 },
expect = {
"bad argument #1 to 'formatDate' (infinite)",
"bad argument #1 to 'formatDate' (infinite)",
"bad argument #1 to 'formatDate' (infinite)",
"language code '[[bogus]]' is invalid",
}
},
{ name = 'lang:formatNum (-Inf)', func = test_method,
args = { 'formatNum', -1/0 },
expect = {
"bad argument #1 to 'formatDate' (infinite)",
"bad argument #1 to 'formatDate' (infinite)",
"bad argument #1 to 'formatDate' (infinite)",
"language code '[[bogus]]' is invalid",
}
},
{ name = 'lang:formatDate', func = test_method,
args = { 'formatDate', 'Y-F-d H:i:s', '20140305123456' },
expect = {