Wikidata: Trim whitespace from start and end of qid in GetEntity [#363]

pull/620/head
gnosygnu 5 years ago
parent 21309d66be
commit a5f8b6e482

@ -59,8 +59,12 @@ public class Xol_lang_itm implements Gfo_invk {
public Xol_lang_itm Fallback_bry_(byte[] v) {
fallback_bry = v;
fallback_bry_ary = Fallbacy_bry_ary__bld(v);
for (byte[] key : fallback_bry_ary) {
fallback_hash.Add_as_key_and_val(String_.new_u8(key));
try {
for (byte[] key : fallback_bry_ary) {
fallback_hash.Add_as_key_and_val(String_.new_u8(key));
}
} catch (Exception exc) {
throw Err_.new_wo_type("failed to add fallback_bry_ary; v=~{0} err=~{1}", v, Err_.Message_gplx_log(exc));
}
return this;
} private byte[] fallback_bry;

@ -267,6 +267,7 @@ public function formatValues( $snaksSerialization ) {
public Wdata_doc Get_wdoc_or_null(Scrib_proc_args args, Scrib_core core, boolean logMissing) {
// get qid / pid from scrib_arg[0]; if none, return null;
byte[] xid_bry = args.Pull_bry(0); if (Bry_.Len_eq_0(xid_bry)) return null; // NOTE: some Modules do not pass in an argument; return early, else spurious warning "invalid qid for ttl" (since ttl is blank); EX:w:Module:Authority_control; DATE:2013-10-27
xid_bry = Bry_.Trim(xid_bry); // trim, b/c some pages will literally pass in "Property:P5\n"; PAGE:de.w:MailandSanremo_2016 ISSUE#:363; DATE:2019-02-12
// get wdoc
Wdata_doc wdoc = entity_mgr.Get_by_xid_or_null(xid_bry); // NOTE: by_xid b/c Module passes just "p1" not "Property:P1"

@ -122,6 +122,19 @@ public class Basic__tst {
, " value=b"
));
}
@Test public void GetEntity_ws() { // PURPOSE: trim, b/c some pages will literally pass in "Property:P5\n"; PAGE:de.w:MailandSanremo_2016 ISSUE#:363; DATE:2019-02-12
wdata_fxt.Init__docs__add(wdata_fxt.Wdoc_bldr("q2").Add_label("en", "b").Xto_wdoc());
fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_wikibase.Invk_getEntity, Object_.Ary(" q2\n\t", false), String_.Concat_lines_nl_skip_last
( "1="
, " id=q2"
, " type=item"
, " schemaVersion=2"
, " labels="
, " en="
, " language=en"
, " value=b"
));
}
// @Test public void GetEntity__missing() { // PURPOSE: missing entity should return empty kv array; PAGE:de.w:Critérium_International_2016 DATE:2017-12-30
// fxt.Test_scrib_proc_str_ary(lib, Scrib_lib_wikibase.Invk_getEntity, Object_.Ary("q2", false), String_.Concat_lines_nl_skip_last
// ( "1=" // not ""

Loading…
Cancel
Save