mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Scribunto
synced 2024-09-23 10:22:54 +00:00
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:
parent
f0c3975e43
commit
078253bd06
|
@ -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] ) ) {
|
||||
|
|
|
@ -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 = {
|
||||
|
|
Loading…
Reference in a new issue