mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
Parser: Trim url-encoded space from the end of a title [#567]
This commit is contained in:
parent
ce5fd232d8
commit
9e302b19b5
@ -447,7 +447,8 @@ public class Xoa_ttl { // PAGE:en.w:http://en.wikipedia.org/wiki/Help:Link; REF.
|
|||||||
}
|
}
|
||||||
if (txt_bb_len == 0) return false;
|
if (txt_bb_len == 0) return false;
|
||||||
if (wik_bgn == -1 && page_bgn == txt_bb_len) return false; // if no wiki, but page_bgn is at end, then ttl is ns only; EX: "Help:"; NOTE: "fr:", "fr:Help" is allowed
|
if (wik_bgn == -1 && page_bgn == txt_bb_len) return false; // if no wiki, but page_bgn is at end, then ttl is ns only; EX: "Help:"; NOTE: "fr:", "fr:Help" is allowed
|
||||||
full_txt = bfr.To_bry_and_clear();
|
full_txt = bfr.To_bry_and_clear_and_trim(); // trim trailing spaces; EX:A  PAGE:it.w:Italo_Toni ISSUE#:567; DATE:2019-09-06
|
||||||
|
if (full_txt.length == 0) return false; // handle  
|
||||||
if ( ns.Case_match() == Xow_ns_case_.Tid__1st
|
if ( ns.Case_match() == Xow_ns_case_.Tid__1st
|
||||||
&& wik_bgn == -1 ) { // do not check case if xwiki; EX: "fr:" would have a wik_bgn of 0 (and a wik_end of 3); "A" (and any non-xwiki ttl) would have a wik_bgn == -1
|
&& wik_bgn == -1 ) { // do not check case if xwiki; EX: "fr:" would have a wik_bgn of 0 (and a wik_end of 3); "A" (and any non-xwiki ttl) would have a wik_bgn == -1
|
||||||
byte char_1st = full_txt[page_bgn];
|
byte char_1st = full_txt[page_bgn];
|
||||||
|
@ -16,7 +16,8 @@ Apache License: https://github.com/gnosygnu/xowa/blob/master/LICENSE-APACHE2.txt
|
|||||||
package gplx.xowa.wikis.ttls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
package gplx.xowa.wikis.ttls; import gplx.*; import gplx.xowa.*; import gplx.xowa.wikis.*;
|
||||||
import org.junit.*; import gplx.xowa.wikis.nss.*;
|
import org.junit.*; import gplx.xowa.wikis.nss.*;
|
||||||
public class Xow_ttl__html_entity_tst {
|
public class Xow_ttl__html_entity_tst {
|
||||||
@Before public void init() {fxt.Reset();} private Xow_ttl_fxt fxt = new Xow_ttl_fxt();
|
private final Xow_ttl_fxt fxt = new Xow_ttl_fxt();
|
||||||
|
@Before public void init() {fxt.Reset();}
|
||||||
@Test public void Eacute() {fxt.Init_ttl("é").Expd_page_txt("é").Test();} //É
|
@Test public void Eacute() {fxt.Init_ttl("é").Expd_page_txt("é").Test();} //É
|
||||||
@Test public void Amp_at_end() {fxt.Init_ttl("Bisc &").Expd_page_txt("Bisc &").Test();}
|
@Test public void Amp_at_end() {fxt.Init_ttl("Bisc &").Expd_page_txt("Bisc &").Test();}
|
||||||
@Test public void Ncr_dec() {fxt.Init_ttl("Ab").Expd_page_txt("Ab").Test();}
|
@Test public void Ncr_dec() {fxt.Init_ttl("Ab").Expd_page_txt("Ab").Test();}
|
||||||
@ -24,4 +25,6 @@ public class Xow_ttl__html_entity_tst {
|
|||||||
// @Test public void Ncr_hex_ns() {fxt.Init_ttl("Help:A").Expd_ns_id(Xow_ns_.Tid__help).Expd_page_txt("A").Test();}
|
// @Test public void Ncr_hex_ns() {fxt.Init_ttl("Help:A").Expd_ns_id(Xow_ns_.Tid__help).Expd_page_txt("A").Test();}
|
||||||
@Test public void Nbsp() {fxt.Init_ttl("A b").Expd_page_txt("A b").Test();} // NOTE:   must convert to space; EX:w:United States [[Image:Dust Bowl - Dallas, South Dakota 1936.jpg|220px|alt=]]
|
@Test public void Nbsp() {fxt.Init_ttl("A b").Expd_page_txt("A b").Test();} // NOTE:   must convert to space; EX:w:United States [[Image:Dust Bowl - Dallas, South Dakota 1936.jpg|220px|alt=]]
|
||||||
@Test public void Amp() {fxt.Init_ttl("A&b").Expd_page_txt("A&b").Test();} // PURPOSE: A&B -> A&B; PAGE:en.w:Amadou Bagayoko?redirect=n; DATE:2014-09-23
|
@Test public void Amp() {fxt.Init_ttl("A&b").Expd_page_txt("A&b").Test();} // PURPOSE: A&B -> A&B; PAGE:en.w:Amadou Bagayoko?redirect=n; DATE:2014-09-23
|
||||||
|
@Test public void Space_only() {fxt.Init_ttl(" ").Expd_invalid_y_().Test();}
|
||||||
|
@Test public void Space_at_end() {fxt.Init_ttl("A ").Expd_page_txt("A").Test();}
|
||||||
}
|
}
|
@ -40,7 +40,7 @@ class Xow_ttl_fxt {
|
|||||||
public Xow_ttl_fxt Expd_base_txt_wo_qarg(String v) {expd_base_txt_wo_qarg = v; return this;} private String expd_base_txt_wo_qarg;
|
public Xow_ttl_fxt Expd_base_txt_wo_qarg(String v) {expd_base_txt_wo_qarg = v; return this;} private String expd_base_txt_wo_qarg;
|
||||||
public Xow_ttl_fxt Expd_leaf_txt_wo_qarg(String v) {expd_leaf_txt_wo_qarg = v; return this;} private String expd_leaf_txt_wo_qarg;
|
public Xow_ttl_fxt Expd_leaf_txt_wo_qarg(String v) {expd_leaf_txt_wo_qarg = v; return this;} private String expd_leaf_txt_wo_qarg;
|
||||||
public Xow_ttl_fxt Expd_force_literal_link(int v) {expd_force_literal_link = v; return this;} private int expd_force_literal_link = -1;
|
public Xow_ttl_fxt Expd_force_literal_link(int v) {expd_force_literal_link = v; return this;} private int expd_force_literal_link = -1;
|
||||||
public Xow_ttl_fxt Expd_err(Gfo_msg_itm v) {expd_err = v; return this;} private Gfo_msg_itm expd_err;
|
public Xow_ttl_fxt Expd_invalid_y_() {expd_invalid = true; return this;} private boolean expd_invalid;
|
||||||
public Xowe_wiki Wiki() {return fxt.Wiki();}
|
public Xowe_wiki Wiki() {return fxt.Wiki();}
|
||||||
public void Reset() {
|
public void Reset() {
|
||||||
fxt.Reset();
|
fxt.Reset();
|
||||||
@ -50,13 +50,18 @@ class Xow_ttl_fxt {
|
|||||||
expd_xwik_txt = expd_full_txt = expd_full_url = expd_page_txt = expd_page_url = expd_leaf_txt = expd_leaf_url = expd_base_txt = expd_base_url
|
expd_xwik_txt = expd_full_txt = expd_full_url = expd_page_txt = expd_page_url = expd_leaf_txt = expd_leaf_url = expd_base_txt = expd_base_url
|
||||||
= expd_root_txt = expd_rest_txt = expd_talk_txt = expd_talk_url = expd_subj_txt = expd_subj_url = expd_anch_txt
|
= expd_root_txt = expd_rest_txt = expd_talk_txt = expd_talk_url = expd_subj_txt = expd_subj_url = expd_anch_txt
|
||||||
= expd_base_txt_wo_qarg = expd_leaf_txt_wo_qarg = expd_qarg_txt = null;
|
= expd_base_txt_wo_qarg = expd_leaf_txt_wo_qarg = expd_qarg_txt = null;
|
||||||
expd_err = null;
|
|
||||||
expd_force_literal_link = -1;
|
expd_force_literal_link = -1;
|
||||||
|
expd_invalid = false;
|
||||||
fxt.Log_clear();
|
fxt.Log_clear();
|
||||||
}
|
}
|
||||||
public void Test() {
|
public void Test() {
|
||||||
Xoa_ttl actl = Xoa_ttl.Parse(fxt.Wiki(), Bry_.new_u8(test_raw));
|
Xoa_ttl actl = Xoa_ttl.Parse(fxt.Wiki(), Bry_.new_u8(test_raw));
|
||||||
if (expd_err == null) {
|
if (expd_invalid) {
|
||||||
|
if (actl == null)
|
||||||
|
return;
|
||||||
|
else
|
||||||
|
Tfds.Fail("invalid expected; " + test_raw);
|
||||||
|
}
|
||||||
if (expd_ns_id != Int_.Min_value) Tfds.Eq(expd_ns_id, actl.Ns().Id(), "ns");
|
if (expd_ns_id != Int_.Min_value) Tfds.Eq(expd_ns_id, actl.Ns().Id(), "ns");
|
||||||
if (expd_xwik_txt != null) Tfds.Eq(expd_xwik_txt, String_.new_u8(actl.Wik_txt()), "Wiki");
|
if (expd_xwik_txt != null) Tfds.Eq(expd_xwik_txt, String_.new_u8(actl.Wik_txt()), "Wiki");
|
||||||
if (expd_page_txt != null) Tfds.Eq(expd_page_txt, String_.new_u8(actl.Page_txt()), "Page_txt");
|
if (expd_page_txt != null) Tfds.Eq(expd_page_txt, String_.new_u8(actl.Page_txt()), "Page_txt");
|
||||||
@ -80,8 +85,4 @@ class Xow_ttl_fxt {
|
|||||||
if (expd_leaf_txt_wo_qarg != null) Tfds.Eq(expd_leaf_txt_wo_qarg, String_.new_u8(actl.Leaf_txt_wo_qarg()), "Expd_leaf_txt_wo_qarg");
|
if (expd_leaf_txt_wo_qarg != null) Tfds.Eq(expd_leaf_txt_wo_qarg, String_.new_u8(actl.Leaf_txt_wo_qarg()), "Expd_leaf_txt_wo_qarg");
|
||||||
if (expd_force_literal_link != -1) Tfds.Eq(expd_force_literal_link == 1, actl.ForceLiteralLink(), "ForceLiteralLink");
|
if (expd_force_literal_link != -1) Tfds.Eq(expd_force_literal_link == 1, actl.ForceLiteralLink(), "ForceLiteralLink");
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
Tfds.Eq_ary(String_.Ary(String_.new_u8(expd_err.Owner().Path()) + "." + String_.new_u8(expd_err.Key_bry())), fxt.Log_xtoAry());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user