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

Parser.Lnke: Escape ampersand in external links [#371]

This commit is contained in:
gnosygnu
2019-03-03 21:20:34 -05:00
parent a70131254f
commit beab14117e
3 changed files with 19 additions and 14 deletions

View File

@@ -51,21 +51,19 @@ public class Xoh_lnke_html {
|| hctx.Mode_is_hdump() // if hdump, never write xwiki format (/site/); always write in url format (https:); note that xwiki is set when wiki is installed locally
|| hctx.Mode_is_file_dump()
) {
if (lnke.Lnke_relative()) { // relative; EX: //a.org
bfr.Add(ctx.Wiki().Utl__url_parser().Url_parser().Relative_url_protocol_bry()).Add_mid(src, href_bgn, href_end);
return true;
// xowa; EX: "xowa:some_cmd"
if (proto_is_xowa) {
bfr.Add(Xop_lnke_wkr.Bry_xowa_protocol);
gfs_encoder.Encode(bfr, src, href_bgn, href_end);
return false;
}
else { // xowa or regular; EX: http://a.org
if (proto_is_xowa) {
bfr.Add(Xop_lnke_wkr.Bry_xowa_protocol);
gfs_encoder.Encode(bfr, src, href_bgn, href_end);
return false;
}
else { // regular; add href
bfr.Add_mid(src, href_bgn, href_end);
return true;
}
// either relative (EX: "//a.org") or regular (EX: "http://a.org")
if (lnke.Lnke_relative()) {
bfr.Add(ctx.Wiki().Utl__url_parser().Url_parser().Relative_url_protocol_bry());
}
Xoh_html_wtr_escaper.Escape(ctx.App().Parser_amp_mgr(), bfr, src, href_bgn, href_end, true, false); // escape & ISSUE#:371; DATE:2019-03-03
return true;
}
else { // xwiki
byte[] xwiki_page_enc = href_encoder.Encode(lnke.Lnke_xwiki_page());

View File

@@ -41,4 +41,11 @@ public class Xoh_lnke_html__basic__tst {
fxt.Test__parse__wtxt_to_html(wtxt, html_https); // https b/c hdump, even though wiki installed
fxt.Hctx_(gplx.xowa.htmls.core.htmls.Xoh_wtr_ctx.Basic);
}
@Test public void Ampersand() {
// relative
fxt.Test_parse_page_wiki_str("[//a.org/b?c1=d1&c2=d2 e]", "<a href=\"https://a.org/b?c1=d1&amp;c2=d2\" rel=\"nofollow\" class=\"external text\">e</a>");
// regular
fxt.Test_parse_page_wiki_str("[https://a.org/b?c1=d1&c2=d2 e]" , "<a href=\"https://a.org/b?c1=d1&amp;c2=d2\" rel=\"nofollow\" class=\"external text\">e</a>");
}
}