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

v2.11.1.1

This commit is contained in:
gnosygnu
2015-11-01 20:50:05 -05:00
parent 4f43f51b18
commit b990ec409f
858 changed files with 6758 additions and 4187 deletions

View File

@@ -1,97 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.parsers.lnkes; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.net.*; import gplx.langs.htmls.encoders.*;
import gplx.xowa.htmls.*; import gplx.xowa.htmls.hrefs.*;
import gplx.xowa.apps.urls.*;
public class Xoh_lnke_wtr {
// private Xoae_app app;
public Xoh_lnke_wtr(Xowe_wiki wiki) {}// this.app = wiki.Appe();}
public void Write_all(Bry_bfr bfr, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_ctx ctx, byte[] src, Xop_lnke_tkn lnke) {
int lnke_bgn = lnke.Lnke_bgn(), lnke_end = lnke.Lnke_end(); boolean proto_is_xowa = lnke.Proto_tid() == Gfo_protocol_itm.Tid_xowa;
if (!hctx.Mode_is_alt()) { // write href, unless mode is alt
if (hctx.Mode_is_hdump()) {
if (lnke.Lnke_typ() == Xop_lnke_tkn.Lnke_typ_text)
bfr.Add_str_a7("<a xtid='a_lnke_txt' href=\"");
else {
if (lnke.Subs_len() == 0)
bfr.Add_str_a7("<a xtid='a_lnke_brk_n' href=\"");
else
bfr.Add_str_a7("<a xtid='a_lnke_brk_y' href=\"");
}
}
else
bfr.Add(Xoh_consts.A_bgn);
if (Write_href(bfr, ctx, src, lnke, lnke_bgn, lnke_end, proto_is_xowa))
bfr.Add(A_lhs_end_external);
else
bfr.Add(A_lhs_end_internal);
}
Write_caption(bfr, html_wtr, hctx, ctx, src, lnke, lnke_bgn, lnke_end, proto_is_xowa);
if (!hctx.Mode_is_alt()) {
if (proto_is_xowa) // add <img />
bfr.Add(Xoh_consts.Img_bgn).Add(html_wtr.Html_mgr().Img_xowa_protocol()).Add(Xoh_consts.__inline_quote);
bfr.Add(Xoh_consts.A_end);
}
}
public boolean Write_href(Bry_bfr bfr, Xop_ctx ctx, byte[] src, Xop_lnke_tkn lnke, int lnke_bgn, int lnke_end, boolean proto_is_xowa) {
byte[] lnke_xwiki_wiki = lnke.Lnke_xwiki_wiki();
if (lnke_xwiki_wiki == null) {
if (lnke.Lnke_relative()) { // relative; EX: //a.org
bfr.Add(ctx.Wiki().Utl__url_parser().Url_parser().Relative_url_protocol_bry()).Add_mid(src, lnke_bgn, lnke_end);
return true;
}
else { // xowa or regular; EX: http://a.org
if (proto_is_xowa) {
bfr.Add(Xop_lnke_wkr.Bry_xowa_protocol);
Xoa_app_.Utl__encoder_mgr().Gfs().Encode(bfr, src, lnke_bgn, lnke_end);
return false;
}
else { // regular; add href
bfr.Add_mid(src, lnke_bgn, lnke_end);
return true;
}
}
}
else { // xwiki
Url_encoder href_encoder = Xoa_app_.Utl__encoder_mgr().Href_quotes();
bfr.Add(Xoh_href_.Bry__site).Add(lnke_xwiki_wiki).Add(Xoh_href_.Bry__wiki)
.Add(href_encoder.Encode(lnke.Lnke_xwiki_page())); // NOTE: must encode page; EX:%22%3D -> '">' which will end attribute; PAGE:en.w:List_of_Category_A_listed_buildings_in_West_Lothian DATE:2014-07-15
if (lnke.Lnke_xwiki_qargs() != null)
Gfo_qarg_mgr.Concat_bfr(bfr, href_encoder, lnke.Lnke_xwiki_qargs()); // NOTE: must encode args
return false;
}
}
public void Write_caption(Bry_bfr bfr, Xoh_html_wtr html_wtr, Xoh_wtr_ctx hctx, Xop_ctx ctx, byte[] src, Xop_lnke_tkn lnke, int lnke_bgn, int lnke_end, boolean proto_is_xowa) {
int subs_len = lnke.Subs_len();
if (subs_len == 0) { // no text; auto-number; EX: "[1]"
if (lnke.Lnke_typ() == Xop_lnke_tkn.Lnke_typ_text)
bfr.Add_mid(src, lnke_bgn, lnke_end);
else
bfr.Add_byte(Byte_ascii.Brack_bgn).Add_int_variable(ctx.Cur_page().Html_data().Lnke_autonumber_next()).Add_byte(Byte_ascii.Brack_end);
}
else { // text available
for (int i = 0; i < subs_len; i++)
html_wtr.Write_tkn(bfr, ctx, hctx, src, lnke, i, lnke.Subs_get(i));
}
}
private static final byte[]
A_lhs_end_external = Bry_.new_a7("\" class=\"external text\" rel=\"nofollow\">")
, A_lhs_end_internal = Bry_.new_a7("\">")
;
}

View File

@@ -1,36 +0,0 @@
/*
XOWA: the XOWA Offline Wiki Application
Copyright (C) 2012 gnosygnu@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.parsers.lnkes; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import org.junit.*;
public class Xoh_lnke_wtr_tst {
private Xop_fxt fxt = new Xop_fxt();
@After public void term() {fxt.Init_para_n_(); fxt.Reset();}
@Test public void Basic() {fxt.Test_parse_page_wiki_str("[irc://a]" , "<a href=\"irc://a\" class=\"external text\" rel=\"nofollow\">[1]</a>");}
@Test public void Autonumber() {fxt.Test_parse_page_wiki_str("[irc://a] [irc://b]" , "<a href=\"irc://a\" class=\"external text\" rel=\"nofollow\">[1]</a> <a href=\"irc://b\" class=\"external text\" rel=\"nofollow\">[2]</a>");}
@Test public void Caption() {fxt.Test_parse_page_wiki_str("[irc://a b]" , "<a href=\"irc://a\" class=\"external text\" rel=\"nofollow\">b</a>");}
@Test public void Caption_wtxt() {fxt.Test_parse_page_wiki_str("[irc://a ''b'']" , "<a href=\"irc://a\" class=\"external text\" rel=\"nofollow\"><i>b</i></a>");}
@Test public void Xowa_protocol() {
String img = "<img src=\"file:///mem/xowa/bin/any/xowa/file/app.general/xowa_exec.png\"/>";
fxt.Wiki().Sys_cfg().Xowa_proto_enabled_(true);
fxt.Test_parse_page_wiki_str("[xowa-cmd:\"a\" z]" , "<a href=\"xowa-cmd:a\">z" + img + "</a>");
fxt.Test_parse_page_wiki_str("[xowa-cmd:\"a.b('c_d');\" z]" , "<a href=\"xowa-cmd:a.b('c_d');\">z" + img + "</a>");
fxt.Test_parse_page_wiki_str("[xowa-cmd:*\"a\"b*c\"* z]" , "<a href=\"xowa-cmd:a%22b%2Ac\">z" + img + "</a>");
fxt.Wiki().Sys_cfg().Xowa_proto_enabled_(false);
fxt.Test_parse_page_wiki_str("[xowa-cmd:\"a\" b]" , "[xowa-cmd:&quot;a&quot; b]"); // protocol is disabled: literalize String (i.e.: don't make it an anchor)
}
}

View File

@@ -16,6 +16,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.parsers.lnkes; import gplx.*; import gplx.xowa.*; import gplx.xowa.parsers.*;
import gplx.core.log_msgs.*;
public class Xop_lnke_log {
private static final Gfo_msg_grp owner = Gfo_msg_grp_.new_(Xoa_app_.Nde, "lnke");
public static final Gfo_msg_itm Dangling = Gfo_msg_itm_.new_note_(owner, "dangling"); // NOTE: WP.BOT:YOBOT;PAGE:en.w:Pan_flute

View File

@@ -27,14 +27,13 @@ public class Xop_lnke_tkn extends Xop_tkn_itm_base {//20111222
public byte[] Lnke_xwiki_page() {return lnke_xwiki_page;} private byte[] lnke_xwiki_page;
public Gfo_qarg_itm[] Lnke_xwiki_qargs() {return lnke_xwiki_qargs;} Gfo_qarg_itm[] lnke_xwiki_qargs;
public void Lnke_xwiki_(byte[] wiki, byte[] page, Gfo_qarg_itm[] args) {this.lnke_xwiki_wiki = wiki; this.lnke_xwiki_page = page; this.lnke_xwiki_qargs = args;}
public int Lnke_bgn() {return lnke_bgn;} private int lnke_bgn;
public int Lnke_end() {return lnke_end;} private int lnke_end;
public Xop_lnke_tkn Lnke_rng_(int bgn, int end) {lnke_bgn = bgn; lnke_end = end; return this;}
public int Lnke_href_bgn() {return lnke_href_bgn;} private int lnke_href_bgn;
public int Lnke_href_end() {return lnke_href_end;} private int lnke_href_end;
public byte[] Protocol() {return protocol;} private byte[] protocol;
public byte Proto_tid() {return proto_tid;} private byte proto_tid;
public Xop_lnke_tkn Subs_add_ary(Xop_tkn_itm... ary) {for (Xop_tkn_itm itm : ary) super.Subs_add(itm); return this;}
public Xop_lnke_tkn(int bgn, int end, byte[] protocol, byte proto_tid, byte lnke_typ, int lnke_bgn, int lnke_end) {
this.Tkn_ini_pos(false, bgn, end); this.protocol = protocol; this.proto_tid = proto_tid; this.lnke_typ = lnke_typ; this.lnke_bgn = lnke_bgn; this.lnke_end = lnke_end;
public Xop_lnke_tkn(int bgn, int end, byte[] protocol, byte proto_tid, byte lnke_typ, int lnke_href_bgn, int lnke_href_end) {
this.Tkn_ini_pos(false, bgn, end); this.protocol = protocol; this.proto_tid = proto_tid; this.lnke_typ = lnke_typ; this.lnke_href_bgn = lnke_href_bgn; this.lnke_href_end = lnke_href_end;
} Xop_lnke_tkn() {}
}

View File

@@ -28,7 +28,7 @@ public class Xop_lnke_wkr implements Xop_ctx_wkr {
// "[" but no "]"; EX: "[irc://a"; NOTE: lnkes that start with protocol will be ac'd in MakeTkn_bgn; EX: "http://a"
Xop_lnke_tkn bgn_tkn = (Xop_lnke_tkn)tkn;
bgn_tkn.Lnke_typ_(Xop_lnke_tkn.Lnke_typ_brack_dangling);
bgn_tkn.Src_end_(bgn_tkn.Lnke_end()); // NOTE: endPos is lnke_end, not cur_pos or src_len; EX: "[irc://a b", lnk ends at a, not b; NOTE: still bgns at [
bgn_tkn.Src_end_(bgn_tkn.Lnke_href_end()); // NOTE: endPos is lnke_end, not cur_pos or src_len; EX: "[irc://a b", lnk ends at a, not b; NOTE: still bgns at [
ctx.Msg_log().Add_itm_none(Xop_lnke_log.Dangling, src, tkn.Src_bgn(), cur_pos);
}
public static final String Str_xowa_protocol = "xowa-cmd:";
@@ -283,7 +283,7 @@ public class Xop_lnke_wkr implements Xop_ctx_wkr {
// NOTE: fmt is [xowa-cmd:^"app.setup_mgr.import_wiki('');"^ ]
if (lnke_type != Xop_lnke_tkn.Lnke_typ_brack) return ctx.Lxr_make_txt_(cur_pos); // NOTE: must check for [ or else C:\xowa\ will cause it to evaluate as lnke
int proto_end_pos = cur_pos + 1; // +1 to skip past :
int lhs_dlm_pos = Bry_find_.Find_fwd(src, Byte_ascii.Quote, proto_end_pos, src_len); if (lhs_dlm_pos == Bry_.NotFound) return ctx.Lxr_make_txt_(cur_pos);
int lhs_dlm_pos = Bry_find_.Find_fwd(src, Byte_ascii.Quote, proto_end_pos, src_len); if (lhs_dlm_pos == Bry_find_.Not_found) return ctx.Lxr_make_txt_(cur_pos);
int lnke_bgn_pos = lhs_dlm_pos + 1;
byte[] rhs_dlm_bry = Bry_quote;
if (lhs_dlm_pos - proto_end_pos > 0) {
@@ -291,9 +291,9 @@ public class Xop_lnke_wkr implements Xop_ctx_wkr {
rhs_dlm_bry = bfr.Add(Bry_quote).Add_mid(src, proto_end_pos, lhs_dlm_pos).To_bry_and_clear();
bfr.Mkr_rls();
}
int rhs_dlm_pos = Bry_find_.Find_fwd(src, rhs_dlm_bry, lnke_bgn_pos, src_len); if (rhs_dlm_pos == Bry_.NotFound) return ctx.Lxr_make_txt_(cur_pos);
int txt_bgn = Bry_find_.Find_fwd_while_space_or_tab(src, rhs_dlm_pos + rhs_dlm_bry.length, src_len); if (txt_bgn == Bry_.NotFound) return ctx.Lxr_make_txt_(cur_pos);
int txt_end = Bry_find_.Find_fwd(src, Byte_ascii.Brack_end, txt_bgn, src_len); if (txt_end == Bry_.NotFound) return ctx.Lxr_make_txt_(cur_pos);
int rhs_dlm_pos = Bry_find_.Find_fwd(src, rhs_dlm_bry, lnke_bgn_pos, src_len); if (rhs_dlm_pos == Bry_find_.Not_found) return ctx.Lxr_make_txt_(cur_pos);
int txt_bgn = Bry_find_.Find_fwd_while_space_or_tab(src, rhs_dlm_pos + rhs_dlm_bry.length, src_len); if (txt_bgn == Bry_find_.Not_found) return ctx.Lxr_make_txt_(cur_pos);
int txt_end = Bry_find_.Find_fwd(src, Byte_ascii.Brack_end, txt_bgn, src_len); if (txt_end == Bry_find_.Not_found) return ctx.Lxr_make_txt_(cur_pos);
int end_pos = txt_end + 1; // +1 to place after ]
Xop_lnke_tkn tkn = tkn_mkr.Lnke(bgn_pos, end_pos, protocol, proto_tid, lnke_type, lnke_bgn_pos, rhs_dlm_pos); // +1 to ignore [

View File

@@ -34,18 +34,18 @@ public class Xop_lnke_wkr_brack_tst {
@Test public void Brace_xnde_bgn() {// PURPOSE: occurred at ref of UK; a {{cite web|url=http://www.abc.gov/{{dead link|date=December 2011}}|title=UK}} b
fxt.Test_parse_page_wiki_str
( "[http://b.org<sup>c</sup>]"
, "<a href=\"http://b.org\" class=\"external text\" rel=\"nofollow\"><sup>c</sup></a>"
, "<a href=\"http://b.org\" rel=\"nofollow\" class=\"external text\"><sup>c</sup></a>"
);
}
@Test public void Brace_newLine() {
fxt.Test_parse_page_wiki("[irc://a\n]", fxt.tkn_txt_(0, 8), fxt.tkn_nl_char_len1_(8), fxt.tkn_txt_(9, 10));
}
@Test public void Html_brack() {
fxt.Test_parse_page_wiki_str("[irc://a]", "<a href=\"irc://a\" class=\"external text\" rel=\"nofollow\">[1]</a>");
fxt.Test_parse_page_wiki_str("[irc://a]", "<a href=\"irc://a\" rel=\"nofollow\" class=\"external autonumber\">[1]</a>");
}
@Test public void Apos() {
fxt.Test_parse_page_wiki_str("[http://www.a.org''b'']", "<a href=\"http://www.a.org\" class=\"external text\" rel=\"nofollow\"><i>b</i></a>");
fxt.Test_parse_page_wiki_str("[http://www.a.org'b]", "<a href=\"http://www.a.org'b\" class=\"external text\" rel=\"nofollow\">[1]</a>");
fxt.Test_parse_page_wiki_str("[http://www.a.org''b'']", "<a href=\"http://www.a.org\" rel=\"nofollow\" class=\"external text\"><i>b</i></a>");
fxt.Test_parse_page_wiki_str("[http://www.a.org'b]", "<a href=\"http://www.a.org'b\" rel=\"nofollow\" class=\"external autonumber\">[1]</a>");
}
@Test public void Nowiki() {
fxt.Test_parse_page_all_str
@@ -57,7 +57,7 @@ public class Xop_lnke_wkr_brack_tst {
fxt.Test_parse_page_wiki_str
( "[http://a.org b [[C]] d]"
,String_.Concat_lines_nl_skip_last
( "<a href=\"http://a.org\" class=\"external text\" rel=\"nofollow\">b <a href=\"/wiki/C\">C</a> d</a>"
( "<a href=\"http://a.org\" rel=\"nofollow\" class=\"external text\">b <a href=\"/wiki/C\">C</a> d</a>"
));
}
@Test public void Encode_xwiki() { // PURPOSE: href title and args should always be encoded; PAGE:en.w:List_of_Category_A_listed_buildings_in_West_Lothian DATE:2014-07-15
@@ -74,21 +74,21 @@ public class Xop_lnke_wkr_brack_tst {
@Test public void Encode_basic() { // PURPOSE: counterpart to Encode_xwiki; DATE:2014-07-15
fxt.Test_parse_page_wiki_str // encode page
( "[http://a.org/%22%3E_A B]"
, "<a href=\"http://a.org/%22%3E_A\" class=\"external text\" rel=\"nofollow\">B</a>" // '%22%3E' not '">'
, "<a href=\"http://a.org/%22%3E_A\" rel=\"nofollow\" class=\"external text\">B</a>" // '%22%3E' not '">'
);
fxt.Test_parse_page_wiki_str // encode args
( "[http://a.org/A?b=%22%3E_C D]"
, "<a href=\"http://a.org/A?b=%22%3E_C\" class=\"external text\" rel=\"nofollow\">D</a>" // '%22%3E' not '">'
, "<a href=\"http://a.org/A?b=%22%3E_C\" rel=\"nofollow\" class=\"external text\">D</a>" // '%22%3E' not '">'
);
}
@Test public void Encode_relative() { // PURPOSE: counterpart to Encode_xwiki; DATE:2014-07-15
fxt.Test_parse_page_wiki_str // encode page
( "[//a.org/%22%3E_A B]"
, "<a href=\"https://a.org/%22%3E_A\" class=\"external text\" rel=\"nofollow\">B</a>" // '%22%3E' not '">'
, "<a href=\"https://a.org/%22%3E_A\" rel=\"nofollow\" class=\"external text\">B</a>" // '%22%3E' not '">'
);
fxt.Test_parse_page_wiki_str // encode args
( "[//a.org/A?b=%22%3E_C D]"
, "<a href=\"https://a.org/A?b=%22%3E_C\" class=\"external text\" rel=\"nofollow\">D</a>" // '%22%3E' not '">'
, "<a href=\"https://a.org/A?b=%22%3E_C\" rel=\"nofollow\" class=\"external text\">D</a>" // '%22%3E' not '">'
);
}
}

View File

@@ -25,7 +25,7 @@ public class Xop_lnke_wkr_relative_tst {
);
}
@Test public void Relative_external() {
fxt.Test_parse_page_wiki_str("[//www.a.org a]", "<a href=\"https://www.a.org\" class=\"external text\" rel=\"nofollow\">a</a>");
fxt.Test_parse_page_wiki_str("[//www.a.org a]", "<a href=\"https://www.a.org\" rel=\"nofollow\" class=\"external text\">a</a>");
}
@Test public void Relative_internal() {
fxt.Init_xwiki_add_user_("en.wikipedia.org");

View File

@@ -23,14 +23,14 @@ public class Xop_lnke_wkr_text_tst {
fxt.Test_parse_page_wiki("irc://a", fxt.tkn_lnke_(0, 7).Lnke_typ_(Xop_lnke_tkn.Lnke_typ_text).Lnke_rng_(0, 7));
}
@Test public void Text_html() {
fxt.Test_parse_page_wiki_str("irc://a", "<a href=\"irc://a\" class=\"external text\" rel=\"nofollow\">irc://a</a>");
fxt.Test_parse_page_wiki_str("irc://a", "<a href=\"irc://a\" rel=\"nofollow\" class=\"external free\">irc://a</a>");
}
@Test public void Text_after() {
fxt.Test_parse_page_wiki("irc://a b c", fxt.tkn_lnke_(0, 7).Lnke_rng_(0, 7), fxt.tkn_space_(7, 8), fxt.tkn_txt_(8, 9), fxt.tkn_space_(9, 10), fxt.tkn_txt_(10, 11));
}
@Test public void Text_before_ascii() { // PURPOSE: free form external urls should not match if preceded by letters; EX:de.w:Sylvie_und_Bruno; DATE:2014-05-11
fxt.Ctx().Lang().Case_mgr_u8_();
String expd_lnke_html = "<a href=\"tel:a\" class=\"external text\" rel=\"nofollow\">tel:a</a>";
String expd_lnke_html = "<a href=\"tel:a\" rel=\"nofollow\" class=\"external free\">tel:a</a>";
fxt.Test_parse_page_wiki_str("titel:a" , "titel:a");
fxt.Test_parse_page_wiki_str(" tel:a" , " " + expd_lnke_html);
fxt.Test_parse_page_wiki_str("!tel:a" , "!" + expd_lnke_html);
@@ -60,21 +60,21 @@ public class Xop_lnke_wkr_text_tst {
, "*irc://b"
),String_.Concat_lines_nl_skip_last
( "<ul>"
, " <li><a href=\"irc://a\" class=\"external text\" rel=\"nofollow\">irc://a</a>"
, " <li><a href=\"irc://a\" rel=\"nofollow\" class=\"external free\">irc://a</a>"
, " </li>"
, " <li><a href=\"irc://b\" class=\"external text\" rel=\"nofollow\">irc://b</a>"
, " <li><a href=\"irc://b\" rel=\"nofollow\" class=\"external free\">irc://b</a>"
, " </li>"
, "</ul>"
));
}
@Test public void Defect_reverse_caption_link() { // PURPOSE: bad lnke formatting (caption before link); ] should show up at end, but only [ shows up; PAGE:en.w:Paul Philippoteaux; [caption http://www.americanheritage.com]
fxt.Test_parse_page_wiki_str("[caption irc://a]", "[caption <a href=\"irc://a\" class=\"external text\" rel=\"nofollow\">irc://a</a>]");
fxt.Test_parse_page_wiki_str("[caption irc://a]", "[caption <a href=\"irc://a\" rel=\"nofollow\" class=\"external free\">irc://a</a>]");
}
@Test public void Lnki() { // PURPOSE: trailing lnki should not get absorbed into lnke; DATE:2014-07-11
fxt.Test_parse_page_wiki_str
( "http://a.org[[B]]" // NOTE: [[ should create another lnki
,String_.Concat_lines_nl_skip_last
( "<a href=\"http://a.org\" class=\"external text\" rel=\"nofollow\">http://a.org</a><a href=\"/wiki/B\">B</a>"
( "<a href=\"http://a.org\" rel=\"nofollow\" class=\"external free\">http://a.org</a><a href=\"/wiki/B\">B</a>"
));
}
@Test public void Protocol_only() { // PURPOSE: protocol only should return text; DATE:2014-10-09
@@ -84,16 +84,16 @@ public class Xop_lnke_wkr_text_tst {
fxt.Test_parse_page_wiki_str("[http:]" , "[http:]");
}
@Test public void Ignore_punctuation_at_end() { // PURPOSE: ignore "," and related punctuation at end; DATE:2014-10-09
fxt.Test_parse_page_wiki_str("http://a.org," , "<a href=\"http://a.org\" class=\"external text\" rel=\"nofollow\">http://a.org</a>,"); // basic
fxt.Test_parse_page_wiki_str("http://a.org,," , "<a href=\"http://a.org\" class=\"external text\" rel=\"nofollow\">http://a.org</a>,,"); // many
fxt.Test_parse_page_wiki_str("http://a.org/b,c" , "<a href=\"http://a.org/b,c\" class=\"external text\" rel=\"nofollow\">http://a.org/b,c</a>"); // do not ignore if in middle
fxt.Test_parse_page_wiki_str("http://a.org:" , "<a href=\"http://a.org\" class=\"external text\" rel=\"nofollow\">http://a.org</a>:"); // colon at end; compare to "http:"
fxt.Test_parse_page_wiki_str("http://a.org," , "<a href=\"http://a.org\" rel=\"nofollow\" class=\"external free\">http://a.org</a>,"); // basic
fxt.Test_parse_page_wiki_str("http://a.org,," , "<a href=\"http://a.org\" rel=\"nofollow\" class=\"external free\">http://a.org</a>,,"); // many
fxt.Test_parse_page_wiki_str("http://a.org/b,c" , "<a href=\"http://a.org/b,c\" rel=\"nofollow\" class=\"external free\">http://a.org/b,c</a>"); // do not ignore if in middle
fxt.Test_parse_page_wiki_str("http://a.org:" , "<a href=\"http://a.org\" rel=\"nofollow\" class=\"external free\">http://a.org</a>:"); // colon at end; compare to "http:"
}
@Test public void Ignore_punctuation_at_end__paren_end() { // PURPOSE: end parent has special rules; DATE:2014-10-10
fxt.Test_parse_page_wiki_str("(http://a.org)" , "(<a href=\"http://a.org\" class=\"external text\" rel=\"nofollow\">http://a.org</a>)"); // trim=y
fxt.Test_parse_page_wiki_str("http://a.org/b(c)", "<a href=\"http://a.org/b(c)\" class=\"external text\" rel=\"nofollow\">http://a.org/b(c)</a>"); // trim=n
fxt.Test_parse_page_wiki_str("(http://a.org)" , "(<a href=\"http://a.org\" rel=\"nofollow\" class=\"external free\">http://a.org</a>)"); // trim=y
fxt.Test_parse_page_wiki_str("http://a.org/b(c)", "<a href=\"http://a.org/b(c)\" rel=\"nofollow\" class=\"external free\">http://a.org/b(c)</a>"); // trim=n
}
@Test public void Sym_quote() { // PURPOSE: quote should interrupt lnke; DATE:2014-10-10
fxt.Test_parse_page_wiki_str("http://a.org/b\"c", "<a href=\"http://a.org/b\" class=\"external text\" rel=\"nofollow\">http://a.org/b</a>&quot;c");
fxt.Test_parse_page_wiki_str("http://a.org/b\"c", "<a href=\"http://a.org/b\" rel=\"nofollow\" class=\"external free\">http://a.org/b</a>&quot;c");
}
}

View File

@@ -43,7 +43,7 @@ public class Xop_lnke_wkr_uncommon_tst {
fxt.Test_parse_page_wiki_str(String_.Concat_lines_nl_skip_last
( "[[http://a.org a]] [[http://b.org b]]"
), String_.Concat_lines_nl_skip_last
( "[<a href=\"http://a.org\" class=\"external text\" rel=\"nofollow\">a</a>] [<a href=\"http://b.org\" class=\"external text\" rel=\"nofollow\">b</a>]"
( "[<a href=\"http://a.org\" rel=\"nofollow\" class=\"external text\">a</a>] [<a href=\"http://b.org\" rel=\"nofollow\" class=\"external text\">b</a>]"
));
}
}

View File

@@ -41,11 +41,11 @@ public class Xop_lnke_wkr_xwiki_tst {
fxt.Test_parse_page_wiki_str("[http://en.wikipedia.org/wiki/A?action=edit a]", "<a href=\"/site/en.wikipedia.org/wiki/A?action=edit\">a</a>");
}
@Test public void Ignore_proto() { // PURPOSE: handle other protocols; PAGE:uk.w:Маскалі; DATE:2015-07-28
fxt.Test_parse_page_wiki_str("[mailto:a b]", "<a href=\"mailto:a\" class=\"external text\" rel=\"nofollow\">b</a>");// should be /w/, not /en.wikipedia.org
fxt.Test_parse_page_wiki_str("[mailto:a b]", "<a href=\"mailto:a\" rel=\"nofollow\" class=\"external text\">b</a>");// should be /w/, not /en.wikipedia.org
}
@Test public void Ignore_alias() { // PURPOSE: fictitious example to make sure aliases are not subbed for domains; DATE:2015-07-28
fxt.Init_xwiki_add_user_("w", "en.wikipedia.org");
fxt.Test_parse_page_wiki_str("[https://w/b c]", "<a href=\"https://w/b\" class=\"external text\" rel=\"nofollow\">c</a>");// should be /w/, not /en.wikipedia.org
fxt.Test_parse_page_wiki_str("[https://w/b c]", "<a href=\"https://w/b\" rel=\"nofollow\" class=\"external text\">c</a>");// should be /w/, not /en.wikipedia.org
}
@Test public void Xwiki__qargs() { // PURPOSE: fix null ref error; PAGE:en.w:Wikipedia:Template_standardisation/demometa DATE:2015-08-02
fxt.Init_xwiki_add_user_("en.wikipedia.org");

View File

@@ -26,8 +26,8 @@ public class Xop_tkn_chkr_lnke extends Xop_tkn_chkr_base {
@Override public int Chk_hook(Tst_mgr mgr, String path, Object actl_obj, int err) {
Xop_lnke_tkn actl = (Xop_lnke_tkn)actl_obj;
err += mgr.Tst_val(lnke_typ == Xop_lnke_tkn.Lnke_typ_null, path, "lnke_typ", lnke_typ, actl.Lnke_typ());
err += mgr.Tst_val(lnke_bgn == -1, path, "lnke_bgn", lnke_bgn, actl.Lnke_bgn());
err += mgr.Tst_val(lnke_end == -1, path, "lnke_end", lnke_end, actl.Lnke_end());
err += mgr.Tst_val(lnke_bgn == -1, path, "lnke_bgn", lnke_bgn, actl.Lnke_href_bgn());
err += mgr.Tst_val(lnke_end == -1, path, "lnke_end", lnke_end, actl.Lnke_href_end());
return err;
}
}