Xtn.Pages: Treat header=0 as false [#622]

staging
gnosygnu 5 years ago
parent d49eda32a8
commit 9d8ab5d206

@ -0,0 +1,40 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.mediawiki; import gplx.*; import gplx.xowa.*;
public class XophpBool {
public static boolean is_true(byte[] val) {return val != null && is_true(String_.new_u8(val));}
public static boolean is_true(String val) {
// REF: https://www.php.net/manual/en/language.types.boolean.php#language.types.boolean.casting
if (String_.Len_eq_0(val)) return false; // the empty String ...
String val_upper = String_.Upper(val);
if (String_.Eq(val_upper, "FALSE")) { // the boolean FALSE itself
return false;
}
double val_double = Double_.parse_or(val, -1); // pick "-1" as marker for invalid doubles; only care about comparing to "0"
// the integers 0 and -0 (zero)
// the floats 0.0 and -0.0 (zero)
// ... and the String "0"
if (val_double == 0) {
return false;
}
// Skip these as they shouldn't render in String serialization
// * an array with zero elements
// * the special type NULL (including unset variables)
// * SimpleXML objects created from empty tags
return true;
}
}

@ -0,0 +1,35 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012-2017 gnosygnu@gmail.com
XOWA is licensed under the terms of the General Public License (GPL) Version 3,
or alternatively under the terms of the Apache License Version 2.0.
You may use XOWA according to either of these licenses as is most appropriate
for your project on a case-by-case basis.
The terms of each license can be found in the source code repository:
GPLv3 License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-GPLv3.txt
Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
*/
package gplx.xowa.mediawiki; import gplx.*; import gplx.xowa.*;
import org.junit.*; import gplx.core.tests.*;
public class XophpBool_tst {
private final XophpBool_fxt fxt = new XophpBool_fxt();
@Test public void is_true() {
fxt.Test__is_true_bry(Bool_.N, null);
fxt.Test__is_true_str(Bool_.N, null, "", "False", "0", "-0", "0.0", "-0.0");
fxt.Test__is_true_str(Bool_.Y, "a", "0.1");
}
}
class XophpBool_fxt {
public void Test__is_true_str(boolean expd, String... ary) {
for (String itm : ary) {
Gftest.Eq__bool(expd, XophpBool.is_true(itm));
}
}
public void Test__is_true_bry(boolean expd, byte[] itm) {
Gftest.Eq__bool(expd, XophpBool.is_true(itm));
}
}

@ -21,6 +21,7 @@ import gplx.xowa.wikis.nss.*;
import gplx.xowa.xtns.lst.*; import gplx.xowa.wikis.pages.*; import gplx.xowa.wikis.data.tbls.*;
import gplx.xowa.parsers.*; import gplx.xowa.parsers.amps.*; import gplx.xowa.parsers.xndes.*; import gplx.xowa.parsers.htmls.*; import gplx.xowa.parsers.lnkis.*; import gplx.xowa.parsers.tmpls.*;
import gplx.xowa.parsers.lnkis.files.*;
import gplx.xowa.mediawiki.*;
public class Pp_pages_nde implements Xox_xnde, Mwh_atr_itm_owner1 {
private boolean xtn_literal = false;
private Xop_root_tkn xtn_root;
@ -123,8 +124,9 @@ public class Pp_pages_nde implements Xox_xnde, Mwh_atr_itm_owner1 {
else {
header = Toc_bry;
}
if (header != null)
if (header != null && XophpBool.is_true(header)) {// check if header is true; ignore values like header=0; ISSUE#:622; DATE:2019-11-28
rv = Bld_wikitext_for_header(full_bfr, index_page, rv);
}
return rv;
} private static final byte[] Toc_bry = Bry_.new_a7("toc");
private byte[] Make_lnki(Bry_bfr full_bfr, byte[] index_page_src, Xop_lnki_tkn lnki) {

@ -152,4 +152,11 @@ public class Pp_pages_nde_hdr_tst {
, "</p>"
));
}
@Test public void Header_is_0() {// PURPOSE: if header is PHP false, ignore; ISSUE#:622 DATE:2019-11-28
// fails if TOC is included ("value=0")
fxt.Test_parse_page_wiki_str("<pages index='A' include=1 header=0/>", String_.Concat_lines_nl
( "<p>&#32;"
, "</p>"
));
}
}

Loading…
Cancel
Save