1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2024-09-29 06:50:50 +00:00

Page_sync: Fix page_sync failing when (a) page has math and (b) math has '~{'

This commit is contained in:
gnosygnu 2016-11-17 16:10:24 -05:00
parent a38c0e834e
commit 9aa3902265
4 changed files with 25 additions and 8 deletions

View File

@ -46,9 +46,14 @@ public class Gfo_usr_dlg_base implements Gfo_usr_dlg {
}
private String Bld_msg_many(String grp_key, String msg_key, String fmt, Object[] args) {
synchronized (tmp_fmtr) {
try {
tmp_fmtr.Fmt_(fmt).Bld_bfr_many(tmp_bfr, args);
return tmp_bfr.To_str_and_clear();
}
catch (Exception e) { // NOTE: can fail if fmt has ~{}; callers should proactively remove, but for now, just return fmt if fails; EX:Page_sync and en.w:Web_crawler; DATE:2016-11-17
return fmt;
}
}
}
private String Bld_msg_one(String grp_key, String msg_key, String fmt, Object val) {
synchronized (tmp_fmtr) {

View File

@ -47,6 +47,8 @@ public class Bry_rdr {
public int Find_fwd_rr() {return Find_fwd(dflt_dlm , Bool_.N, Bool_.N, Fail_if_missing);}
public int Find_fwd_rr(byte find) {return Find_fwd(find , Bool_.N, Bool_.N, Fail_if_missing);}
public int Find_fwd_rr(byte[] find) {return Find_fwd(find , Bool_.N, Bool_.N, Fail_if_missing);}
public int Find_fwd_rr_or(byte[] find, int or)
{return Find_fwd(find , Bool_.N, Bool_.N, or);}
private int Find_fwd(byte find, boolean ret_lhs, boolean pos_lhs, int or) {
int find_pos = Bry_find_.Find_fwd(src, find, pos, src_end);
if (find_pos == Bry_find_.Not_found) {

View File

@ -22,7 +22,7 @@ import gplx.langs.htmls.*; import gplx.langs.htmls.docs.*;
import gplx.xowa.wikis.domains.*;
public class Xoh_img_src_data implements Bfr_arg_clearable, Xoh_itm_parser {
private final Bry_rdr rdr = new Bry_rdr().Dflt_dlm_(Byte_ascii.Slash);
public void Fail_throws_err_(boolean v) {rdr.Fail_throws_err_(v);}// TEST
private boolean fail_throws_err;
public byte[] Src_bry() {return src_bry;} private byte[] src_bry;
public int Src_bgn() {return src_bgn;} private int src_bgn;
public int Src_end() {return src_end;} private int src_end;
@ -60,8 +60,8 @@ public class Xoh_img_src_data implements Bfr_arg_clearable, Xoh_itm_parser {
if (src_end == src_bgn) return true; // empty src; just return true;
// get repo_bgn; note that some <img> may be hiero / enlarge / magnify and should exit
rdr.Init_by_wkr(err_wkr, "img.src.xowa", src_bgn, src_end).Fail_throws_err_(Bool_.N);
repo_bgn = rdr.Find_fwd_rr(Bry__file);
rdr.Init_by_wkr(err_wkr, "img.src.xowa", src_bgn, src_end).Fail_throws_err_(fail_throws_err);
repo_bgn = rdr.Find_fwd_rr_or(Bry__file, -1);
if (repo_bgn == -1) {
repo_bgn = rdr.Find_fwd_rr(Bry__math);
if (repo_bgn == Bry_find_.Not_found) return false;
@ -131,6 +131,11 @@ public class Xoh_img_src_data implements Bfr_arg_clearable, Xoh_itm_parser {
}
return rdr.Move_to(pos);
}
public void Fail_throws_err_(boolean v) {// TEST
this.fail_throws_err = v;
rdr.Fail_throws_err_(v);
}
private static final byte[] Bry__file = Bry_.new_a7("/file/"), Bry__math = Bry_.new_a7("/math/"), Bry__orig = Bry_.new_a7("orig/"), Bry__thumb = Bry_.new_a7("thumb/");
private static final byte Tid__orig = 1, Tid__thumb = 2;
private static final Btrie_slim_mgr trie = Btrie_slim_mgr.cs().Add_bry_byte(Bry__orig, Tid__orig).Add_bry_byte(Bry__thumb, Tid__thumb);

View File

@ -34,6 +34,9 @@ public class Xoh_img_src_data_tst {
@Test public void Md5_depth_4() {
fxt.Test__parse("file:///C:/xowa/file/en.wikipedia.org/orig/7/0/1/0/A.png" , "en.wikipedia.org" , Bool_.Y, "A.png", -1, -1, -1);
}
@Test public void Math() { // PURPOSE: "xowa:/math" shouldn't cause img_src_parser to fail; DATE:2016-11-17
fxt.Test__parse("xowa:/math/596f8baf206a81478afd4194b44138715dc1a05c" , "en.wikipedia.org" , Bool_.Y, "A.png", -1, -1, -1);
}
// @Test public void Fail__orig_mode() {
// fxt.Test__parse__fail("file:///C:/xowa/file/commons.wikimedia.org/fail/7/0/A.png", "failed trie check: mid='fail/7/0/A.png' ctx='Main_Page' wkr='img.src.xowa' excerpt='file:///C:/xowa/file/commons.wikimedia.org/fail/7/0/A.png'");
// }
@ -49,7 +52,9 @@ class Xoh_img_src_data_fxt extends Xoh_itm_parser_fxt { private final Xoh_im
@Override public Xoh_itm_parser Parser_get() {return parser;}
public void Test__parse(String src_str, String expd_repo, boolean expd_file_is_orig, String expd_file, int expd_w, int expd_time, int expd_page) {
Exec_parse(src_str);
if (parser.Repo_end() != -1) // need for Math()
Tfds.Eq_str(expd_repo, String_.new_u8(src, parser.Repo_bgn(), parser.Repo_end()));
if (parser.File_ttl_end() != -1) // need for Math()
Tfds.Eq_str(expd_file, String_.new_u8(src, parser.File_ttl_bgn(), parser.File_ttl_end()));
Tfds.Eq_bool(expd_file_is_orig, parser.File_is_orig());
Tfds.Eq_int(expd_w, parser.File_w());
@ -57,7 +62,7 @@ class Xoh_img_src_data_fxt extends Xoh_itm_parser_fxt { private final Xoh_im
Tfds.Eq_int(expd_page, parser.File_page());
}
@Override public void Exec_parse_hook(Bry_err_wkr err_wkr, Xoh_hdoc_ctx hctx, int src_bgn, int src_end) {
// Xoh_hdoc_ctx hctx
parser.Fail_throws_err_(true);
parser.Parse(err_wkr, new Xoh_hdoc_ctx(), Xow_domain_itm_.Bry__enwiki, src_bgn, src_end);
}
}