mirror of
https://github.com/gnosygnu/xowa.git
synced 2024-10-27 20:34:16 +00:00
Scribunto: Encode key / val in GetUrl [#465]
This commit is contained in:
parent
648cd4944a
commit
42dbaff1d2
@ -24,6 +24,10 @@ NOTE.1: This is a liberal translation of /includes/parser/CoreParserFunctions.ph
|
||||
|
||||
NOTE.2: Both fullurle: and localurle: performed additional character escaping on the resulting link, but no example is known where that still has any additional effect.
|
||||
REF: http://meta.wikimedia.org/wiki/Help:Parser_function
|
||||
|
||||
NOTE.3: For query_args, Title.php|fixUrlQueryArgs will call wfArrayToCgi to urlencode if $query is array. However, if $query is String, it does nothing
|
||||
To match this behavior, qry_arg should be an Object, but this is a significant change (not to mention loosening type-rules)
|
||||
Instead, assuming that only Scribunto functions will be using qry_arg as an array, and putting wfArrayToCgi logic in Extract_qry_args instead of here
|
||||
*/
|
||||
public class Pfunc_urlfunc extends Pf_func_base {
|
||||
@Override public boolean Func_require_colon_arg() {return true;}
|
||||
|
@ -45,6 +45,19 @@ public class Scrib_lib_title_tst {
|
||||
@Test public void GetUrl__args_many() { // PUPROSE: GetUrl sometimes passes in kvs for qry_args; fr.w:Wikipédia:Image_du_jour/Date; DATE:2013-12-24
|
||||
fxt.Test__proc__objs__flat(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "canonicalUrl", Keyval_.Ary(Keyval_.new_("action", "edit"), Keyval_.new_("preload", "b"))), "https://en.wikipedia.org/wiki/Main_Page?action=edit&preload=b");
|
||||
}
|
||||
@Test public void GetUrl__args_encode() { // PUPROSE: GetUrl should url-encode arguments; ISSUE#:465 DATE:2019-05-18
|
||||
// NOTE: tested with following
|
||||
// =mw.title.makeTitle("Template", "A"):fullUrl{"a / b", "c / d"}
|
||||
// //en.wikipedia.org/w/index.php?title=Template:A&1=a+%2F+b&2=c+%2F+d
|
||||
// =mw.title.makeTitle("Template", "A"):fullUrl("a / b=c / d")
|
||||
// //en.wikipedia.org/w/index.php?title=Template:A&a / b=c / d
|
||||
|
||||
// encode if array
|
||||
fxt.Test__proc__objs__flat(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "fullUrl", Keyval_.Ary(Keyval_.new_("a / b", "c / d"))), "//en.wikipedia.org/wiki/Main_Page?a+%2F+b=c+%2F+d");
|
||||
|
||||
// do not encode if String
|
||||
fxt.Test__proc__objs__flat(lib, Scrib_lib_title.Invk_getUrl, Object_.Ary("Main_Page", "fullUrl", "a / b=c / d"), "//en.wikipedia.org/wiki/Main_Page?a / b=c / d");
|
||||
}
|
||||
@Test public void MakeTitle() {
|
||||
fxt.Test__proc__objs__nest(lib, Scrib_lib_title.Invk_makeTitle, Object_.Ary("Module", "A") , ttl_fast(828, "Module", "A"));
|
||||
fxt.Test__proc__objs__nest(lib, Scrib_lib_title.Invk_makeTitle, Object_.Ary(828, "A") , ttl_fast(828, "Module", "A"));
|
||||
|
@ -31,6 +31,19 @@ public class Scrib_lib_uri_tst {
|
||||
@Test public void Url__args_many() { // PUPROSE: GetUrl sometimes passes in kvs for qry_args; it.w:Astronomie; DATE:2014-01-18
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_fullUrl, Object_.Ary("A", Keyval_.Ary(Keyval_.new_("action", "edit"))), "//en.wikipedia.org/wiki/A?action=edit");
|
||||
}
|
||||
@Test public void Url__args_encode() { // PUPROSE: GetUrl should url-encode arguments; ISSUE#:465 DATE:2019-05-18
|
||||
// NOTE: tested with following
|
||||
// =mw.uri.fullUrl("A", {"b / c", "d / e"})
|
||||
// en.wikipedia.org/w/index.php?title=A&b+%2F+c=d+%2F+e
|
||||
// =mw.uri.fullUrl("A", "b / c=d / e")
|
||||
// en.wikipedia.org/w/index.php?title=A&b+%2F+c=d+%2F+e {still encoded b/c of mw.uri.lua}
|
||||
|
||||
// encode if array
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_fullUrl, Object_.Ary("A", Keyval_.Ary(Keyval_.new_("a / b", "c / d"))), "//en.wikipedia.org/wiki/A?a+%2F+b=c+%2F+d");
|
||||
|
||||
// do not encode if String
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_fullUrl, Object_.Ary("A", "a / b=c / d"), "//en.wikipedia.org/wiki/A?a / b=c / d");
|
||||
}
|
||||
@Test public void AnchorEncode() {
|
||||
fxt.Test_scrib_proc_str(lib, Scrib_lib_uri.Invk_anchorEncode , Object_.Ary("[irc://a b c]" ), "b_c");
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ 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.xtns.scribunto.procs; import gplx.*; import gplx.xowa.*; import gplx.xowa.xtns.*; import gplx.xowa.xtns.scribunto.*;
|
||||
import gplx.langs.htmls.encoders.*;
|
||||
public class Scrib_proc_args {
|
||||
private Keyval[] ary; private int ary_len;
|
||||
public Scrib_proc_args(Keyval[] v) {
|
||||
@ -156,15 +157,16 @@ public class Scrib_proc_args {
|
||||
if (qry_args_cls == String.class)
|
||||
return Bry_.new_u8((String)qry_args_obj);
|
||||
else if (qry_args_cls == Keyval[].class) {
|
||||
// ISSUE#:465; SEE:Pfunc_urlfunc; DATE:2019-05-18
|
||||
Bry_bfr bfr = wiki.Utl__bfr_mkr().Get_b128();
|
||||
Keyval[] kvs = (Keyval[])qry_args_obj;
|
||||
int len = kvs.length;
|
||||
for (int i = 0; i < len; i++) {
|
||||
Keyval kv = kvs[i];
|
||||
if (i != 0) bfr.Add_byte(Byte_ascii.Amp);
|
||||
bfr.Add_str_u8(kv.Key());
|
||||
Gfo_url_encoder_.Php_urlencode.Encode(bfr, Bry_.new_u8(kv.Key()));
|
||||
bfr.Add_byte(Byte_ascii.Eq);
|
||||
bfr.Add_str_u8(kv.Val_to_str_or_empty());
|
||||
Gfo_url_encoder_.Php_urlencode.Encode(bfr, kv.Val_to_bry());
|
||||
}
|
||||
return bfr.To_bry_and_rls();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user