1
0
mirror of https://github.com/gnosygnu/xowa.git synced 2026-03-02 03:49:30 +00:00

'v3.7.3.1'

This commit is contained in:
gnosygnu
2016-07-17 21:10:59 -04:00
parent b333db45f8
commit 7a851a41a5
290 changed files with 3048 additions and 2124 deletions

View File

@@ -18,6 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.parsers.xndes; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.primitives.*; import gplx.core.btries.*; import gplx.xowa.parsers.htmls.*;
public class Xop_xatr_whitelist_mgr {
private final Hash_adp_bry grp_hash = Hash_adp_bry.cs();
private final Btrie_rv trv = new Btrie_rv();
public boolean Chk(int tag_id, byte[] src, Mwh_atr_itm xatr) {
byte[] key_bry = xatr.Key_bry();
byte[] chk_bry; int chk_bgn, chk_end;
@@ -32,13 +34,13 @@ public class Xop_xatr_whitelist_mgr {
chk_bgn = 0;
chk_end = key_bry.length;
}
Object o = key_trie.Match_bgn(chk_bry, chk_bgn, chk_end);
Object o = key_trie.Match_at(trv, chk_bry, chk_bgn, chk_end);
if (o == null) return false;// unknown atr_key; EX: <b unknown=1/>
Xop_xatr_whitelist_itm itm = (Xop_xatr_whitelist_itm)o;
byte itm_key_tid = itm.Key_tid();
xatr.Key_tid_(itm_key_tid);
boolean rv = itm.Tags()[tag_id] == 1 // is atr allowed for tag
&& (itm.Exact() ? key_trie.Match_pos() == chk_end : true) // if exact, check for exact; else always true
&& (itm.Exact() ? trv.Pos() == chk_end : true) // if exact, check for exact; else always true
;
switch (itm_key_tid) {
case Mwh_atr_itm_.Key_tid__style:
@@ -52,79 +54,78 @@ public class Xop_xatr_whitelist_mgr {
return rv;
}
public Xop_xatr_whitelist_mgr Ini() { // REF.MW:Sanitizer.php|setupAttributeWhitelist
Ini_grp("common" , null , "id", "class", "lang", "dir", "title", "style", "role");
Ini_grp("block" , "common" , "align");
Ini_grp("tablealign" , null , "align", "char", "charoff", "valign");
Ini_grp("tablecell" , null , "abbr", "axis", "headers", "scope", "rowspan", "colspan", "nowrap", "width", "height", "bgcolor");
Ini_grp("common" , null , "id", "class", "lang", "dir", "title", "style", "role");
Ini_grp("block" , "common" , "align");
Ini_grp("tablealign" , null , "align", "char", "charoff", "valign");
Ini_grp("tablecell" , null , "abbr", "axis", "headers", "scope", "rowspan", "colspan", "nowrap", "width", "height", "bgcolor");
Ini_nde(Xop_xnde_tag_.Tid__div , "block");
Ini_nde(Xop_xnde_tag_.Tid__center , "common");
Ini_nde(Xop_xnde_tag_.Tid__span , "block");
Ini_nde(Xop_xnde_tag_.Tid__h1 , "block");
Ini_nde(Xop_xnde_tag_.Tid__h2 , "block");
Ini_nde(Xop_xnde_tag_.Tid__h3 , "block");
Ini_nde(Xop_xnde_tag_.Tid__h4 , "block");
Ini_nde(Xop_xnde_tag_.Tid__h5 , "block");
Ini_nde(Xop_xnde_tag_.Tid__h6 , "block");
Ini_nde(Xop_xnde_tag_.Tid__em , "common");
Ini_nde(Xop_xnde_tag_.Tid__strong , "common");
Ini_nde(Xop_xnde_tag_.Tid__cite , "common");
Ini_nde(Xop_xnde_tag_.Tid__dfn , "common");
Ini_nde(Xop_xnde_tag_.Tid__code , "common");
Ini_nde(Xop_xnde_tag_.Tid__samp , "common");
Ini_nde(Xop_xnde_tag_.Tid__kbd , "common");
Ini_nde(Xop_xnde_tag_.Tid__var , "common");
Ini_nde(Xop_xnde_tag_.Tid__abbr , "common");
Ini_nde(Xop_xnde_tag_.Tid__blockquote , "common", "cite");
Ini_nde(Xop_xnde_tag_.Tid__sub , "common");
Ini_nde(Xop_xnde_tag_.Tid__sup , "common");
Ini_nde(Xop_xnde_tag_.Tid__p , "block");
Ini_nde(Xop_xnde_tag_.Tid__br , "id", "class", "title", "style", "clear");
Ini_nde(Xop_xnde_tag_.Tid__pre , "common", "width");
Ini_nde(Xop_xnde_tag_.Tid__ins , "common", "cite", "datetime");
Ini_nde(Xop_xnde_tag_.Tid__del , "common", "cite", "datetime");
Ini_nde(Xop_xnde_tag_.Tid__ul , "common", "type");
Ini_nde(Xop_xnde_tag_.Tid__ol , "common", "type", "start");
Ini_nde(Xop_xnde_tag_.Tid__li , "common", "type", "value");
Ini_nde(Xop_xnde_tag_.Tid__dl , "common");
Ini_nde(Xop_xnde_tag_.Tid__dd , "common");
Ini_nde(Xop_xnde_tag_.Tid__dt , "common");
Ini_nde(Xop_xnde_tag_.Tid__table , "common", "summary", "width", "border", "frame", "rules", "cellspacing", "cellpadding", "align", "bgcolor");
Ini_nde(Xop_xnde_tag_.Tid__caption , "common", "align");
Ini_nde(Xop_xnde_tag_.Tid__thead , "common", "tablealign");
Ini_nde(Xop_xnde_tag_.Tid__tfoot , "common", "tablealign");
Ini_nde(Xop_xnde_tag_.Tid__tbody , "common", "tablealign");
Ini_nde(Xop_xnde_tag_.Tid__colgroup , "common", "span", "width", "tablealign");
Ini_nde(Xop_xnde_tag_.Tid__col , "common", "span", "width", "tablealign");
Ini_nde(Xop_xnde_tag_.Tid__tr , "common", "bgcolor", "tablealign");
Ini_nde(Xop_xnde_tag_.Tid__td , "common", "tablecell", "tablealign");
Ini_nde(Xop_xnde_tag_.Tid__th , "common", "tablecell", "tablealign");
Ini_nde(Xop_xnde_tag_.Tid__a , "common", "href", "rel", "rev");
Ini_nde(Xop_xnde_tag_.Tid__img , "common", "alt", "src", "width", "height");
Ini_nde(Xop_xnde_tag_.Tid__tt , "common");
Ini_nde(Xop_xnde_tag_.Tid__b , "common");
Ini_nde(Xop_xnde_tag_.Tid__i , "common");
Ini_nde(Xop_xnde_tag_.Tid__big , "common");
Ini_nde(Xop_xnde_tag_.Tid__small , "common");
Ini_nde(Xop_xnde_tag_.Tid__strike , "common");
Ini_nde(Xop_xnde_tag_.Tid__s , "common");
Ini_nde(Xop_xnde_tag_.Tid__u , "common");
Ini_nde(Xop_xnde_tag_.Tid__font , "common", "size", "color", "face");
Ini_nde(Xop_xnde_tag_.Tid__hr , "common", "noshade", "size", "width");
Ini_nde(Xop_xnde_tag_.Tid__ruby , "common");
Ini_nde(Xop_xnde_tag_.Tid__rb , "common");
Ini_nde(Xop_xnde_tag_.Tid__rt , "common");
Ini_nde(Xop_xnde_tag_.Tid__rp , "common");
Ini_nde(Xop_xnde_tag_.Tid__math , "class", "style", "id", "title");
Ini_nde(Xop_xnde_tag_.Tid__time , "class", "datetime");
Ini_nde(Xop_xnde_tag_.Tid__bdi , "common");
Ini_nde(Xop_xnde_tag_.Tid__data , "common", "value");
Ini_nde(Xop_xnde_tag_.Tid__mark , "common");
Ini_nde(Xop_xnde_tag_.Tid__q , "common");
Ini_nde(Xop_xnde_tag_.Tid__div , "block");
Ini_nde(Xop_xnde_tag_.Tid__center , "common");
Ini_nde(Xop_xnde_tag_.Tid__span , "block");
Ini_nde(Xop_xnde_tag_.Tid__h1 , "block");
Ini_nde(Xop_xnde_tag_.Tid__h2 , "block");
Ini_nde(Xop_xnde_tag_.Tid__h3 , "block");
Ini_nde(Xop_xnde_tag_.Tid__h4 , "block");
Ini_nde(Xop_xnde_tag_.Tid__h5 , "block");
Ini_nde(Xop_xnde_tag_.Tid__h6 , "block");
Ini_nde(Xop_xnde_tag_.Tid__em , "common");
Ini_nde(Xop_xnde_tag_.Tid__strong , "common");
Ini_nde(Xop_xnde_tag_.Tid__cite , "common");
Ini_nde(Xop_xnde_tag_.Tid__dfn , "common");
Ini_nde(Xop_xnde_tag_.Tid__code , "common");
Ini_nde(Xop_xnde_tag_.Tid__samp , "common");
Ini_nde(Xop_xnde_tag_.Tid__kbd , "common");
Ini_nde(Xop_xnde_tag_.Tid__var , "common");
Ini_nde(Xop_xnde_tag_.Tid__abbr , "common");
Ini_nde(Xop_xnde_tag_.Tid__blockquote , "common", "cite");
Ini_nde(Xop_xnde_tag_.Tid__sub , "common");
Ini_nde(Xop_xnde_tag_.Tid__sup , "common");
Ini_nde(Xop_xnde_tag_.Tid__p , "block");
Ini_nde(Xop_xnde_tag_.Tid__br , "id", "class", "title", "style", "clear");
Ini_nde(Xop_xnde_tag_.Tid__pre , "common", "width");
Ini_nde(Xop_xnde_tag_.Tid__ins , "common", "cite", "datetime");
Ini_nde(Xop_xnde_tag_.Tid__del , "common", "cite", "datetime");
Ini_nde(Xop_xnde_tag_.Tid__ul , "common", "type");
Ini_nde(Xop_xnde_tag_.Tid__ol , "common", "type", "start");
Ini_nde(Xop_xnde_tag_.Tid__li , "common", "type", "value");
Ini_nde(Xop_xnde_tag_.Tid__dl , "common");
Ini_nde(Xop_xnde_tag_.Tid__dd , "common");
Ini_nde(Xop_xnde_tag_.Tid__dt , "common");
Ini_nde(Xop_xnde_tag_.Tid__table , "common", "summary", "width", "border", "frame", "rules", "cellspacing", "cellpadding", "align", "bgcolor");
Ini_nde(Xop_xnde_tag_.Tid__caption , "common", "align");
Ini_nde(Xop_xnde_tag_.Tid__thead , "common", "tablealign");
Ini_nde(Xop_xnde_tag_.Tid__tfoot , "common", "tablealign");
Ini_nde(Xop_xnde_tag_.Tid__tbody , "common", "tablealign");
Ini_nde(Xop_xnde_tag_.Tid__colgroup , "common", "span", "width", "tablealign");
Ini_nde(Xop_xnde_tag_.Tid__col , "common", "span", "width", "tablealign");
Ini_nde(Xop_xnde_tag_.Tid__tr , "common", "bgcolor", "tablealign");
Ini_nde(Xop_xnde_tag_.Tid__td , "common", "tablecell", "tablealign");
Ini_nde(Xop_xnde_tag_.Tid__th , "common", "tablecell", "tablealign");
Ini_nde(Xop_xnde_tag_.Tid__a , "common", "href", "rel", "rev");
Ini_nde(Xop_xnde_tag_.Tid__img , "common", "alt", "src", "width", "height");
Ini_nde(Xop_xnde_tag_.Tid__tt , "common");
Ini_nde(Xop_xnde_tag_.Tid__b , "common");
Ini_nde(Xop_xnde_tag_.Tid__i , "common");
Ini_nde(Xop_xnde_tag_.Tid__big , "common");
Ini_nde(Xop_xnde_tag_.Tid__small , "common");
Ini_nde(Xop_xnde_tag_.Tid__strike , "common");
Ini_nde(Xop_xnde_tag_.Tid__s , "common");
Ini_nde(Xop_xnde_tag_.Tid__u , "common");
Ini_nde(Xop_xnde_tag_.Tid__font , "common", "size", "color", "face");
Ini_nde(Xop_xnde_tag_.Tid__hr , "common", "noshade", "size", "width");
Ini_nde(Xop_xnde_tag_.Tid__ruby , "common");
Ini_nde(Xop_xnde_tag_.Tid__rb , "common");
Ini_nde(Xop_xnde_tag_.Tid__rt , "common");
Ini_nde(Xop_xnde_tag_.Tid__rp , "common");
Ini_nde(Xop_xnde_tag_.Tid__math , "class", "style", "id", "title");
Ini_nde(Xop_xnde_tag_.Tid__time , "class", "datetime");
Ini_nde(Xop_xnde_tag_.Tid__bdi , "common");
Ini_nde(Xop_xnde_tag_.Tid__data , "common", "value");
Ini_nde(Xop_xnde_tag_.Tid__mark , "common");
Ini_nde(Xop_xnde_tag_.Tid__q , "common");
Ini_all_loose("data");
return this;
}
private Hash_adp_bry grp_hash = Hash_adp_bry.cs();
private void Ini_grp(String key_str, String base_grp, String... cur_itms) {
byte[][] itms = Bry_.Ary(cur_itms);
if (base_grp != null)
@@ -196,11 +197,11 @@ public class Xop_xatr_whitelist_mgr {
}
int pos = chk_bgn;
while (pos < chk_end) {
Object o = style_trie.Match_bgn(chk_bry, pos, chk_end);
Object o = style_trie.Match_at(trv, chk_bry, pos, chk_end);
if (o == null)
++pos;
else {
pos = style_trie.Match_pos();
pos = trv.Pos();
byte style_tid = ((Byte_obj_val)o).Val();
switch (style_tid) {
case Style_expression:
@@ -243,7 +244,7 @@ public class Xop_xatr_whitelist_mgr {
return Byte_ascii.Null;
}
static final byte Style_expression = 0, Style_filter = 1, Style_accelerator = 2, Style_url = 3, Style_urls = 4, Style_comment = 5, Style_image = 6, Style_image_set = 7;
private static Btrie_slim_mgr style_trie = Btrie_slim_mgr.ci_a7() // NOTE:ci.ascii:Javascript
private static final Btrie_slim_mgr style_trie = Btrie_slim_mgr.ci_a7() // NOTE:ci.ascii:Javascript
.Add_str_byte("expression" , Style_expression)
.Add_str_byte("filter" , Style_filter)
.Add_str_byte("accelerator" , Style_accelerator)

View File

@@ -26,10 +26,10 @@ public class Xop_xnde_tag_regy {
public Btrie_slim_mgr Get_trie(int i) {
if (init_needed) Init_by_hash(null); // TEST:
switch (i) {
case Xop_parser_.Parse_tid_tmpl: return trie_tmpl;
case Xop_parser_.Parse_tid_page_tmpl: return trie_wtxt_tmpl;
case Xop_parser_.Parse_tid_page_wiki: return trie_wtxt_main;
case Xop_parser_.Parse_tid_null: default: return trie_wtxt_tmpl; // TODO_OLD: should throw Err_.new_unhandled(i);
case Xop_parser_tid_.Tid__defn: return trie_tmpl;
case Xop_parser_tid_.Tid__tmpl: return trie_wtxt_tmpl;
case Xop_parser_tid_.Tid__wtxt: return trie_wtxt_main;
case Xop_parser_tid_.Tid__null: default: return trie_wtxt_tmpl; // TODO_OLD: should throw Err_.new_unhandled(i);
}
}
public void Init_by_meta(Hash_adp_bry xtn_hash) {Init_by_hash(xtn_hash);}

View File

@@ -108,7 +108,7 @@ public class Xop_xnde_wkr implements Xop_ctx_wkr {
break;
}
if (tag_obj == null) { // not a known xml tag; EX: "<abcd>"; "if 5 < 7 then"
if (ctx.Parse_tid() == Xop_parser_.Parse_tid_page_wiki) {
if (ctx.Parse_tid() == Xop_parser_tid_.Tid__wtxt) {
if (ctx_cur_tid_is_tblw_atr_owner) // unknown_tag is occurring inside tblw element (EX: {| style='margin:1em<f'); just add to txt tkn
return ctx.Lxr_make_txt_(cur_pos);
else { // unknown_tag is occurring anywhere else; escape < to &lt; and resume from character just after it;
@@ -150,7 +150,7 @@ public class Xop_xnde_wkr implements Xop_ctx_wkr {
}
else { // is a <nowiki> skip to </nowiki>
if ( i == end_name_pos
&& ctx.Parse_tid() == Xop_parser_.Parse_tid_tmpl
&& ctx.Parse_tid() == Xop_parser_tid_.Tid__defn
&& Bry_.Eq(atr_parser.Bry_obj().Val(), Xop_xnde_tag_.Tag__includeonly.Name_bry())
) {
pre2_hack = true;
@@ -175,7 +175,7 @@ public class Xop_xnde_wkr implements Xop_ctx_wkr {
boolean force_xtn_for_nowiki = false;
int end_pos = gt_pos + 1;
switch (ctx.Parse_tid()) { // NOTE: special logic to handle <include>; SEE: NOTE_1 below
case Xop_parser_.Parse_tid_page_wiki: // NOTE: ignore if (a) wiki and (b) <noinclude> or <onlyinclude>
case Xop_parser_tid_.Tid__wtxt: // NOTE: ignore if (a) wiki and (b) <noinclude> or <onlyinclude>
switch (tag.Id()) {
case Xop_xnde_tag_.Tid__noinclude:
case Xop_xnde_tag_.Tid__onlyinclude:
@@ -187,7 +187,7 @@ public class Xop_xnde_wkr implements Xop_ctx_wkr {
break;
}
break;
case Xop_parser_.Parse_tid_tmpl: // NOTE: ignore if (a) tmpl and (b) <includeonly>
case Xop_parser_tid_.Tid__defn: // NOTE: ignore if (a) tmpl and (b) <includeonly>
switch (tag.Id()) {
case Xop_xnde_tag_.Tid__includeonly:
ctx.Subs_add(root, tkn_mkr.Ignore(bgn_pos, end_pos, Xop_ignore_tkn.Ignore_tid_include_tmpl));
@@ -203,7 +203,7 @@ public class Xop_xnde_wkr implements Xop_ctx_wkr {
break;
}
break;
case Xop_parser_.Parse_tid_page_tmpl: // NOTE: added late; SEE:comment test for "a <!-<noinclude></noinclude>- b -->c"
case Xop_parser_tid_.Tid__tmpl: // NOTE: added late; SEE:comment test for "a <!-<noinclude></noinclude>- b -->c"
switch (tag.Id()) {
case Xop_xnde_tag_.Tid__noinclude:
ctx.Subs_add(root, tkn_mkr.Ignore(bgn_pos, end_pos, Xop_ignore_tkn.Ignore_tid_include_tmpl));
@@ -301,11 +301,11 @@ public class Xop_xnde_wkr implements Xop_ctx_wkr {
break;
}
Mwh_atr_itm[] atrs = null;
if (ctx.Parse_tid() == Xop_parser_.Parse_tid_page_wiki) {
if (ctx.Parse_tid() == Xop_parser_tid_.Tid__wtxt) {
atrs = ctx.App().Parser_mgr().Xnde__parse_atrs(src, atrs_bgn, atrs_end);
}
if (( ( tag.Xtn()
&& ( ctx.Parse_tid() != Xop_parser_.Parse_tid_tmpl // do not gobble up rest if in tmpl; handle <poem>{{{1}}}</poem>; DATE:2014-03-03
&& ( ctx.Parse_tid() != Xop_parser_tid_.Tid__defn // do not gobble up rest if in tmpl; handle <poem>{{{1}}}</poem>; DATE:2014-03-03
|| tag.Xtn_skips_template_args() // ignore above if tag specifically skips template args; EX: <pre>; DATE:2014-04-10
)
)
@@ -595,7 +595,7 @@ public class Xop_xnde_wkr implements Xop_ctx_wkr {
xnde.Subs_add(tkn_mkr.Txt(open_end, close_bgn));
}
switch (ctx.Parse_tid()) {
case Xop_parser_.Parse_tid_page_tmpl: {
case Xop_parser_tid_.Tid__tmpl: {
Xox_xnde xnde_xtn = null;
switch (tag.Id()) {
case Xop_xnde_tag_.Tid__xowa_cmd: xnde_xtn = tkn_mkr.Xnde__xowa_cmd(); break;
@@ -606,7 +606,7 @@ public class Xop_xnde_wkr implements Xop_ctx_wkr {
}
break;
}
case Xop_parser_.Parse_tid_page_wiki: {
case Xop_parser_tid_.Tid__wtxt: {
Xox_xnde xnde_xtn = null;
int tag_id = tag.Id();
boolean escaped = false;