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

'v3.9.4.1'

This commit is contained in:
gnosygnu
2016-09-25 22:05:47 -04:00
parent 35d78f6106
commit e3b393650d
211 changed files with 3148 additions and 2197 deletions

View File

@@ -94,6 +94,7 @@ public class Xoa_cmd_arg_mgr {
case Op_sys.Tid_lnx: rv = "linux"; break;
case Op_sys.Tid_wnt: rv = "windows"; break;
case Op_sys.Tid_osx: rv = "macosx"; break;
case Op_sys.Tid_arm: rv = "arm"; break;
default: throw Err_.new_unhandled("unknown platform " + Op_sys.Cur());
}
if (op_sys.Bitness() == Op_sys.Bitness_64) rv += "_64";

View File

@@ -35,8 +35,14 @@ public class Xoa_cfg_db_txt implements Xoa_cfg_db {
bfr.ClearAndReset();
} private Bry_bfr bfr = Bry_bfr_.New();
public void Cfg_save_end(Xoa_cfg_mgr cfg_mgr) {
Xoa_app_.Usr_dlg().Log_many("", "", "shutting down app; saving cfg: len=~{0}", bfr.Len());
Io_mgr.Instance.SaveFilBfr(Cfg_url(cfg_mgr), bfr);
Io_url cfg_url = Cfg_url(cfg_mgr);
if (Io_mgr.Instance.QueryFil(cfg_url).ReadOnly()) {
Xoa_app_.Usr_dlg().Log_many("", "", "shutting down app; skipping cfg b/c file is marked read-only; src=~{0}", cfg_url);
}
else {
Xoa_app_.Usr_dlg().Log_many("", "", "shutting down app; saving cfg: len=~{0}", bfr.Len());
Io_mgr.Instance.SaveFilBfr(Cfg_url(cfg_mgr), bfr);
}
}
public void Cfg_save_run(Xoa_cfg_mgr cfg_mgr, Xoa_cfg_grp cfg_grp, Xoa_cfg_itm cfg_itm) {
fmtr.Bld_bfr_many(bfr, Xoa_gfs_wtr_.Escape(cfg_grp.Key_bry()), Xoa_gfs_wtr_.Escape(cfg_itm.Key()), Xoa_gfs_wtr_.Escape(cfg_itm.Val()));

View File

@@ -18,8 +18,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
package gplx.xowa.apps.gfs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import gplx.core.brys.fmtrs.*;
import gplx.langs.phps.*;
public class Xoa_gfs_php_mgr {
public static byte[] Xto_php(Bry_bfr bfr, boolean escape_backslash, byte[] src) {
public class Gfs_php_converter {
public static byte[] Xto_php(Bry_bfr bfr, boolean escape_backslash, byte[] src) {
int len = src.length;
int pos = 0;
boolean dirty = false;
@@ -87,26 +87,54 @@ public class Xoa_gfs_php_mgr {
}
}
}
public static byte[] Xto_gfs(Bry_bfr bfr, byte[] raw) {
public static byte[] To_gfs(Bry_bfr bfr, byte[] raw) {
int raw_len = raw.length;
for (int i = 0; i < raw_len; i++) {
for (int i = 0; i < raw_len; ++i) {
byte b = raw[i];
switch (b) {
case Byte_ascii.Backslash:
case Byte_ascii.Backslash: // unescape; EX: '\"' -> '"'
++i;
if (i < raw_len)
bfr.Add_byte(raw[i]);
else
if (i < raw_len){
byte escape_byte = raw[i];
switch (escape_byte) { // REF: http://php.net/manual/en/language.types.String.php
case Byte_ascii.Ltr_t: escape_byte = Byte_ascii.Tab; break;
case Byte_ascii.Ltr_n: escape_byte = Byte_ascii.Nl; break;
case Byte_ascii.Ltr_r: escape_byte = Byte_ascii.Cr; break;
case Byte_ascii.Ltr_v: escape_byte = 11; break; // 11=vertical tab
case Byte_ascii.Ltr_e: escape_byte = 27; break; // 27=escape
case Byte_ascii.Ltr_f: escape_byte = 12; break; // 12=form fed
case Byte_ascii.Backslash:
case Byte_ascii.Quote:
case Byte_ascii.Apos:
case Byte_ascii.Dollar: break;
// FUTURE:
// //\[0-7]{1,3} the sequence of characters matching the regular expression is a character in octal notation, which silently overflows to fit in a byte (e.g. "\400" === "\000")
// \ x[0-9A-Fa-f]{1,2} the sequence of characters matching the regular expression is a character in hexadecimal notation
// \ u{[0-9A-Fa-f]+} the sequence of characters matching the regular expression is a Unicode codepoint, which will be output to the String as that codepoint's UTF-8 representation (added in PHP 7.0.0)
default: // all else seems to be rendered literally; EX:"You do not need to put \ before a /."; PAGE:en.w:MediaWiki:Spam-whitelist; DATE:2016-09-12
bfr.Add_byte(Byte_ascii.Backslash);
bfr.Add_byte(escape_byte);
continue;
}
bfr.Add_byte(escape_byte);
}
else // if eos, just output "\"; don't fail; EX: "a\" -> "a\"
bfr.Add_byte(Byte_ascii.Backslash);
break;
case Byte_ascii.Tilde:
case Byte_ascii.Tilde: // double up tilde; EX: '~' -> '~~'
bfr.Add_byte_repeat(Bry_fmtr.char_escape, 2); // escape tilde; EX: ~u -> ~~u; DATE:2013-11-11
break;
case Byte_ascii.Dollar:
int end_pos = Php_text_itm_parser.Find_fwd_non_int(raw, i + 1, raw_len);
int int_val = Bry_.To_int_or(raw, i + 1, end_pos, -1);
bfr.Add_byte(Bry_fmtr.char_escape).Add_byte(Bry_fmtr.char_arg_bgn).Add_int_variable(int_val - 1).Add_byte(Bry_fmtr.char_arg_end);
i = end_pos - 1;
case Byte_ascii.Dollar: // convert php args to gfs args; EX: $1 -> ~{0}
int int_bgn = i + 1;
int int_end = Php_text_itm_parser.Find_fwd_non_int(raw, int_bgn, raw_len);
if (int_bgn == int_end ) // no numbers after $; EX: "$ "; "$a"
bfr.Add_byte(b);
else {
int int_val = Bry_.To_int_or(raw, int_bgn, int_end, -1);
if (int_val == -1) throw Err_.new_wo_type(String_.Format("unknown php dollar sequence: raw=~{0}", raw));
bfr.Add_byte(Bry_fmtr.char_escape).Add_byte(Bry_fmtr.char_arg_bgn).Add_int_variable(int_val - List_adp_.Base1).Add_byte(Bry_fmtr.char_arg_end); // convert "$1" -> "~{0}"
i = int_end - 1; // -1 b/c Find_fwd_non_int positions after non-int
}
break;
default:
bfr.Add_byte(b);

View File

@@ -0,0 +1,55 @@
/*
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.apps.gfs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import org.junit.*;
public class Gfs_php_converter__to_gfs__tst {
@Before public void init() {fxt.Clear();} private final Gfs_php_converter_fxt fxt = new Gfs_php_converter_fxt();
@Test public void Escape_sequences() {
fxt.Test__to_gfs("a\\\"b" , "a\"b");
fxt.Test__to_gfs("a\\'b" , "a'b");
fxt.Test__to_gfs("a\\$b" , "a$b");
fxt.Test__to_gfs("a\\\\b" , "a\\b");
fxt.Test__to_gfs("a\\nb" , "a\nb");
fxt.Test__to_gfs("a\\tb" , "a\tb");
fxt.Test__to_gfs("a\\rb" , "a\rb");
fxt.Test__to_gfs("a\\ b" , "a\\ b"); // "\ " seems to be rendered literally; EX:"You do not need to put \ before a /."; PAGE:en.w:MediaWiki:Spam-whitelist; DATE:2016-09-12
fxt.Test__to_gfs("a\\\\b\\'c\\\"d\\$e" , "a\\b'c\"d$e"); // backslash.escape
fxt.Test__to_gfs("\\" , "\\"); // backslash.eos; eos, but nothing to escape; render self but dont fail
}
@Test public void Tilde() {
fxt.Test__to_gfs("a~b" , "a~~b"); // tilde.escape
}
@Test public void Arguments() {
fxt.Test__to_gfs("a$1b" , "a~{0}b"); // dollar
fxt.Test__to_gfs("a $ b" , "a $ b"); // noop
}
}
class Gfs_php_converter_fxt {
private final Bry_bfr bfr = Bry_bfr_.New();
public void Clear() {}
public void Test__to_gfs(String raw, String expd) {
byte[] actl = Gfs_php_converter.To_gfs(bfr, Bry_.new_u8(raw));
Tfds.Eq(expd, String_.new_u8(actl));
}
public void Test_Xto_php_escape_y(String raw, String expd) {Test_Xto_php(raw, Bool_.Y, expd);}
public void Test_Xto_php_escape_n(String raw, String expd) {Test_Xto_php(raw, Bool_.N, expd);}
public void Test_Xto_php(String raw, boolean escape_backslash, String expd) {
byte[] actl = Gfs_php_converter.Xto_php(bfr, escape_backslash, Bry_.new_u8(raw));
Tfds.Eq(expd, String_.new_u8(actl));
}
}

View File

@@ -17,14 +17,8 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package gplx.xowa.apps.gfs; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import org.junit.*;
public class Xoa_gfs_php_mgr_tst {
@Before public void init() {fxt.Clear();} private Xoa_gfs_php_mgr_fxt fxt = new Xoa_gfs_php_mgr_fxt();
@Test public void Xto_gfs() {
fxt.Test_Xto_gfs("a\\\\b\\'c\\\"d\\$e" , "a\\b'c\"d$e"); // backslash.escape
fxt.Test_Xto_gfs("\\" , "\\"); // backslash.eos; eos, but nothing to escape; render self but dont fail
fxt.Test_Xto_gfs("a~b" , "a~~b"); // tilde.escape
fxt.Test_Xto_gfs("a$1b" , "a~{0}b"); // dollar
}
public class Gfs_php_converter__to_php__tst {
@Before public void init() {fxt.Clear();} private final Gfs_php_converter_fxt fxt = new Gfs_php_converter_fxt();
@Test public void Xto_php() {
fxt.Test_Xto_php_escape_y("a~{0}b" , "a$1b"); // tilde.arg.one
fxt.Test_Xto_php_escape_y("a~{0}b~{1}c~{2}d" , "a$1b$2c$3d"); // tilde.arg.many
@@ -34,17 +28,3 @@ public class Xoa_gfs_php_mgr_tst {
fxt.Test_Xto_php_escape_n("a\\b'c\"d$e" , "a\\b'c\"d$e"); // backslash.escape_n
}
}
class Xoa_gfs_php_mgr_fxt {
private Bry_bfr bfr = Bry_bfr_.New();
public void Clear() {}
public void Test_Xto_gfs(String raw, String expd) {
byte[] actl = Xoa_gfs_php_mgr.Xto_gfs(bfr, Bry_.new_u8(raw));
Tfds.Eq(expd, String_.new_u8(actl));
}
public void Test_Xto_php_escape_y(String raw, String expd) {Test_Xto_php(raw, Bool_.Y, expd);}
public void Test_Xto_php_escape_n(String raw, String expd) {Test_Xto_php(raw, Bool_.N, expd);}
public void Test_Xto_php(String raw, boolean escape_backslash, String expd) {
byte[] actl = Xoa_gfs_php_mgr.Xto_php(bfr, escape_backslash, Bry_.new_u8(raw));
Tfds.Eq(expd, String_.new_u8(actl));
}
}

View File

@@ -28,7 +28,7 @@ class Xoa_site_cfg_itm__interwikimap extends Xoa_site_cfg_itm__base {
if (i != 0) bfr.Add_byte_nl();
byte[] iw_key = nde.Get_bry_or_null("prefix"); if (iw_key == null) throw Err_.new_("site_meta", "invalid interwiki", "key", iw_key);
byte[] iw_url = nde.Get_bry_or_null("url"); if (iw_url == null) throw Err_.new_("site_meta", "invalid interwiki", "url", iw_key);
bfr.Add(iw_key).Add_byte_pipe().Add(Xoa_gfs_php_mgr.Xto_gfs(tmp_bfr, iw_url));
bfr.Add(iw_key).Add_byte_pipe().Add(Gfs_php_converter.To_gfs(tmp_bfr, iw_url));
}
@Override public void Exec_csv(Xow_wiki wiki, int loader_tid, byte[] dsv_bry) {
if (loader_tid == Xoa_site_cfg_loader_.Tid__fallback)

View File

@@ -15,23 +15,39 @@ 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.apps.urls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
public class Xoa_url_encoder {
package gplx.xowa.apps.utls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
public class Xoa_url_encoder { // NOTE: redundant with Gfo_url_encoder, but is simpler; DATE:2016-09-15
private final Bry_bfr bfr = Bry_bfr_.New();
public byte[] Encode(byte[] src) {
int src_len = src.length;
for (int i = 0; i < src_len; i++) {
boolean dirty = false;
for (int i = 0; i < src_len; ++i) {
byte b = src[i];
byte[] repl = null;
switch (b) {
case Byte_ascii.Space: bfr.Add(Bry__underline); break;
case Byte_ascii.Amp: bfr.Add(Bry__amp); break;
case Byte_ascii.Apos: bfr.Add(Bry__apos); break;
case Byte_ascii.Eq: bfr.Add(Bry__eq); break;
case Byte_ascii.Plus: bfr.Add(Bry__plus); break;
default: bfr.Add_byte(b); break;
case Byte_ascii.Space: repl = Bry__underline; break;
case Byte_ascii.Amp: repl = Bry__amp; break;
case Byte_ascii.Apos: repl = Bry__apos; break;
case Byte_ascii.Eq: repl = Bry__eq; break;
case Byte_ascii.Plus: repl = Bry__plus; break;
}
// not a replacement sequence
if (repl == null) {
// if dirty, add to bfr; else, ignore
if (dirty)
bfr.Add_byte(b);
}
else {
// if clean, add everything before cur_pos to bfr
if (!dirty) {
bfr.Add_mid(src, 0, i);
dirty = true;
}
bfr.Add(repl);
}
}
return bfr.To_bry_and_clear();
return dirty ? bfr.To_bry_and_clear() : src;
}
private static final byte[] Bry__amp = Bry_.new_a7("%26"), Bry__eq = Bry_.new_a7("%3D")
, Bry__plus = Bry_.new_a7("%2B"), Bry__apos = Bry_.new_a7("%27")

View File

@@ -0,0 +1,31 @@
/*
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.apps.utls; import gplx.*; import gplx.xowa.*; import gplx.xowa.apps.*;
import org.junit.*; import gplx.core.tests.*;
public class Xoa_url_encoder__tst {
private final Xoa_url_encoder__fxt fxt = new Xoa_url_encoder__fxt();
@Test public void Syms__diff() {fxt.Test__encode(" &'=+", "_%26%27%3D%2B");}
@Test public void Syms__same() {fxt.Test__encode("!\"#$%()*,-./:;<>?@[\\]^_`{|}~", "!\"#$%()*,-./:;<>?@[\\]^_`{|}~");}
@Test public void Mixed() {fxt.Test__encode("a &'=+b", "a_%26%27%3D%2Bb");} // PURPOSE: make sure dirty flag is set
}
class Xoa_url_encoder__fxt {
private final Xoa_url_encoder encoder = new Xoa_url_encoder();
public void Test__encode(String raw, String expd) {
Gftest.Eq__bry(Bry_.new_u8(expd), encoder.Encode(Bry_.new_u8(raw)));
}
}