From 811e5474313fc8fc959bee1a58e51c4c55f350ec Mon Sep 17 00:00:00 2001 From: Adam Chlipala Date: Thu, 24 Dec 2009 10:44:53 -0500 Subject: Proper JavaScript-side URI escaping/de-escaping; fix C-side URL encoding of big characters --- lib/js/urweb.js | 5 ++--- src/c/urweb.c | 6 +++--- tests/jsuni.ur | 17 +++++++++++++++++ tests/jsuni.urp | 3 +++ tests/jsuni.urs | 1 + 5 files changed, 26 insertions(+), 6 deletions(-) create mode 100644 tests/jsuni.ur create mode 100644 tests/jsuni.urp create mode 100644 tests/jsuni.urs diff --git a/lib/js/urweb.js b/lib/js/urweb.js index 15c9df7e..bd575cc9 100644 --- a/lib/js/urweb.js +++ b/lib/js/urweb.js @@ -583,8 +583,7 @@ function pflo(s) { function uf(s) { if (s.length == 0) return "_"; - return (s.charAt(0) == '_' ? "_" : "") - + escape(s).replace(new RegExp ("/", "g"), "%2F").replace(new RegExp ("\\+", "g"), "%2B"); + return (s.charAt(0) == '_' ? "_" : "") + encodeURIComponent(s); } function uu(s) { @@ -592,7 +591,7 @@ function uu(s) { s = s.substring(1); } else if (s.length >= 3 && s.charAt(0) == '%' && s.charAt(1) == '5' && (s.charAt(2) == 'f' || s.charAt(2) == 'F')) s = s.substring(3); - return unescape(s.replace(new RegExp ("\\+", "g"), " ")); + return decodeURIComponent(s.replace(new RegExp ("\\+", "g"), " ")); } function ub(b) { diff --git a/src/c/urweb.c b/src/c/urweb.c index 472f6eb4..1f8271d5 100644 --- a/src/c/urweb.c +++ b/src/c/urweb.c @@ -1590,7 +1590,7 @@ char *uw_Basis_urlifyString(uw_context ctx, uw_Basis_string s) { *p++ = '_'; for (; *s; s++) { - char c = *s; + unsigned char c = *s; if (c == ' ') *p++ = '+'; @@ -1667,7 +1667,7 @@ uw_unit uw_Basis_urlifyString_w(uw_context ctx, uw_Basis_string s) { uw_writec_unsafe(ctx, '_'); for (; *s; s++) { - char c = *s; + unsigned char c = *s; if (c == ' ') uw_writec_unsafe(ctx, '+'); @@ -1737,7 +1737,7 @@ static uw_Basis_string uw_unurlifyString_to(int fromClient, uw_context ctx, char } for (s1 = r; *s2; ++s1, ++s2) { - char c = *s2; + unsigned char c = *s2; switch (c) { case '+': diff --git a/tests/jsuni.ur b/tests/jsuni.ur new file mode 100644 index 00000000..9a1e3e90 --- /dev/null +++ b/tests/jsuni.ur @@ -0,0 +1,17 @@ +fun main () = + s1 <- source ""; + s2 <- source ""; + + let + fun echo s = return s + + fun echoer () = + v1 <- get s1; + v1' <- rpc (echo v1); + set s2 v1' + in + return +
+