1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

Scribunto: Fix script error 'NullPointerException' on a few en.w pages

This commit is contained in:
gnosygnu
2017-11-29 23:10:44 -05:00
parent 539a6fad6a
commit e30828a270
5 changed files with 33 additions and 2 deletions

View File

@@ -63,6 +63,10 @@ public class Xot_invk_mock implements Xot_invk {
int len = args.length;
for (int i = 0; i < len; i++) {
Keyval kv = args[i];
// handle null kv; PAGE:en.w:Abziri DATE:2017-11-29
if (kv == null) continue;
String kv_key_str = kv.Key();
Object kv_key_obj = kv.Key_as_obj();
Arg_nde_tkn_mock nde_tkn = null;

View File

@@ -228,8 +228,13 @@ class Scrib_lua_rsp_bldr {
bfr.Add_str_a7("a:").Add_int_variable(len).Add_str_a7(":{");
for (int i = 0; i < len; i++) {
Keyval kv = ary[i];
Bld_obj(bfr, kv.Key_as_obj());
Bld_obj(bfr, kv.Val());
if (kv == null) { // handle null kv; PAGE:en.w:Abziri DATE:2017-11-29
Bld_obj(bfr, gplx.langs.phps.Php_srl_parser.NULL_ARRAY_ITEM);
}
else {
Bld_obj(bfr, kv.Key_as_obj());
Bld_obj(bfr, kv.Val());
}
}
bfr.Add_byte(Byte_ascii.Curly_end);
}

View File

@@ -388,6 +388,15 @@ class Scrib_lib_mw_callParserFunction_sorter implements gplx.core.lists.Comparer
public int compare(Object lhsObj, Object rhsObj) {
Keyval lhs = (Keyval)lhsObj;
Keyval rhs = (Keyval)rhsObj;
// handle null kv; PAGE:en.w:Abziri DATE:2017-11-29
if (lhs == null && rhs == null)
return CompareAble_.Same;
else if (lhs == null)
return CompareAble_.More;
else if (rhs == null)
return CompareAble_.Less;
Object lhs_key = lhs.Key_as_obj();
Object rhs_key = rhs.Key_as_obj();
boolean lhs_is_int = Type_.Eq(lhs_key.getClass(), Int_.Cls_ref_type);

View File

@@ -87,6 +87,10 @@ public class Scrib_lib_mw__invoke_tst {
fxt.Test_lib_proc_kv(lib, Scrib_lib_mw.Invk_callParserFunction, Scrib_kv_utl_.base1_many_ary_("current", "DISPLAYTITLE", "''a''"), "");
Tfds.Eq("<i>a</i>", String_.new_a7(fxt.Parser_fxt().Ctx().Page().Html_data().Display_ttl()));
}
@Test public void CallParserFunction__null() { // PURPOSE.fix: null arg should not fail; PAGE:en.w:Abziri DATE:2017-11-29
fxt.Init_page("{{#invoke:Mod_0|Prc_0}}");
fxt.Test_lib_proc_kv(lib, Scrib_lib_mw.Invk_callParserFunction, Scrib_kv_utl_.flat_many_(1, "current", 2, "#coordinates", 3, Keyval_.Ary(Keyval_.int_(1, "a"), Keyval_.int_(3, "b"), null)), "");// failed with NullPointerException
}
@Test public void ExpandTemplate_tmpl() {
fxt.Init_page("{{#invoke:Mod_0|Prc_0}}");
fxt.Parser_fxt().Data_create("Template:A", "b{{{key1}}}c");