mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
Language: Check if lang exists in fallback hash before adding it [#330]
This commit is contained in:
parent
e744c5123a
commit
c383f2a231
@ -61,10 +61,11 @@ public class Xol_lang_itm implements Gfo_invk {
|
||||
fallback_bry_ary = Fallbacy_bry_ary__bld(v);
|
||||
try {
|
||||
for (byte[] key : fallback_bry_ary) {
|
||||
fallback_hash.Add_as_key_and_val(String_.new_u8(key));
|
||||
String val = String_.new_u8(key);
|
||||
fallback_hash.Add_if_dupe_use_1st(val, val);
|
||||
}
|
||||
} catch (Exception exc) {
|
||||
String[] cur_fallbacks = (String[])fallback_hash.To_ary(String.class);
|
||||
String cur_fallbacks = String_.AryXtoStr((String[])fallback_hash.To_ary(String.class));
|
||||
throw Err_.new_wo_type(String_.Format("failed to add fallback_bry_ary; lang={0} cur_fallbacks={1} new_fallbacks={2} err={3}", key_str, cur_fallbacks, v, Err_.Message_gplx_log(exc)));
|
||||
}
|
||||
return this;
|
||||
|
39
400_xowa/src/gplx/xowa/langs/Xol_lang_itm_tst.java
Normal file
39
400_xowa/src/gplx/xowa/langs/Xol_lang_itm_tst.java
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
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.langs; import gplx.*; import gplx.xowa.*;
|
||||
import org.junit.*; import gplx.core.tests.*;
|
||||
public class Xol_lang_itm_tst {
|
||||
private final Xol_lang_itm_fxt fxt = new Xol_lang_itm_fxt();
|
||||
@Before public void init() {fxt.Clear();}
|
||||
@Test public void Fallback_bry__dupes() { // ISSUE#:330; DATE:2019-02-17
|
||||
Xol_lang_itm lang = fxt.Make("qqq");
|
||||
fxt.Init_fallback_bry(lang, "en");
|
||||
fxt.Init_fallback_bry(lang, "en"); // duplicate call would throw error; note that dupes can happen b/c "en" is default language; EX: isRTL("gl") -> "pt-br,en" -> "pt,en"
|
||||
Gftest.Eq__str("en", lang.Fallback_bry());
|
||||
}
|
||||
}
|
||||
class Xol_lang_itm_fxt {
|
||||
private Xop_fxt fxt;
|
||||
public void Clear() {
|
||||
fxt = new Xop_fxt();
|
||||
}
|
||||
public Xol_lang_itm Make(String code) {
|
||||
return new Xol_lang_itm(fxt.App().Lang_mgr(), Bry_.new_a7(code));
|
||||
}
|
||||
public void Init_fallback_bry(Xol_lang_itm lang, String itm) {
|
||||
lang.Fallback_bry_(Bry_.new_u8(itm));
|
||||
}
|
||||
}
|
@ -263,13 +263,7 @@ public class Scrib_lib_language implements Scrib_lib {
|
||||
}
|
||||
private Xol_lang_itm lang_(Scrib_proc_args args) {
|
||||
byte[] lang_code = args.Cast_bry_or_null(0);
|
||||
Xol_lang_itm lang = null;
|
||||
try {
|
||||
lang = lang_code == null ? null : core.App().Lang_mgr().Get_by_or_load(lang_code);
|
||||
}
|
||||
catch (Exception exc) {
|
||||
throw Err_.new_wo_type("mw.lang: Unable to get lang", "page", core.Page().Url_bry_safe(), "lang", lang_code, "err", Err_.Message_gplx_log(exc));
|
||||
}
|
||||
Xol_lang_itm lang = lang_code == null ? null : core.App().Lang_mgr().Get_by_or_load(lang_code);
|
||||
if (lang == null) throw Err_.new_wo_type("lang_code is not valid", "lang_code", String_.new_u8(lang_code));
|
||||
return lang;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user