# HG changeset patch # User Adam Chlipala # Date 1252762310 14400 # Node ID 552c989c16017e1828d6b454226b1c81b4bb4a52 # Parent 803342eb2dc07b61b3fb775fc3defa3e0c6a4412 Change string URLification to avoid using the empty string, which confuses Apache no2slash() diff -r 803342eb2dc0 -r 552c989c1601 lib/js/urweb.js --- a/lib/js/urweb.js Thu Sep 10 14:55:27 2009 -0400 +++ b/lib/js/urweb.js Sat Sep 12 09:31:50 2009 -0400 @@ -464,10 +464,15 @@ } function uf(s) { - return escape(s).replace(new RegExp ("/", "g"), "%2F").replace(new RegExp ("\\+", "g"), "%2B"); + if (s.length == 0) + return "_"; + return (s[0] == '_' ? "_" : "") + + escape(s).replace(new RegExp ("/", "g"), "%2F").replace(new RegExp ("\\+", "g"), "%2B"); } function uu(s) { + if (s.length > 0 && s[0] == '_') + s = s.substring(1); return unescape(s.replace(new RegExp ("\\+", "g"), " ")); } diff -r 803342eb2dc0 -r 552c989c1601 src/c/urweb.c --- a/src/c/urweb.c Thu Sep 10 14:55:27 2009 -0400 +++ b/src/c/urweb.c Sat Sep 12 09:31:50 2009 -0400 @@ -1479,9 +1479,16 @@ char *uw_Basis_urlifyString(uw_context ctx, uw_Basis_string s) { char *r, *p; - uw_check_heap(ctx, strlen(s) * 3 + 1); - - for (r = p = ctx->heap.front; *s; s++) { + if (s[0] == '\0') + return "_"; + + uw_check_heap(ctx, strlen(s) * 3 + 1 + !!(s[0] == '_')); + + r = p = ctx->heap.front; + if (s[0] == '_') + *p++ = '_'; + + for (; *s; s++) { char c = *s; if (c == ' ') @@ -1547,7 +1554,16 @@ } uw_unit uw_Basis_urlifyString_w(uw_context ctx, uw_Basis_string s) { - uw_check(ctx, strlen(s) * 3); + if (s[0] == '\0') { + uw_check(ctx, 1); + uw_writec_unsafe(ctx, '_'); + return uw_unit_v; + } + + uw_check(ctx, strlen(s) * 3 + !!(s[0] == '_')); + + if (s[0] == '_') + uw_writec_unsafe(ctx, '_'); for (; *s; s++) { char c = *s; @@ -1612,6 +1628,11 @@ char *s1, *s2; int n; + if (*s2 == '_') + ++s2; + else if (s2[0] == '%' && s2[1] == '5' && (s2[2] == 'f' || s2[2] == 'F')) + s2 += 3; + for (s1 = r, s2 = s; *s2; ++s1, ++s2) { char c = *s2; diff -r 803342eb2dc0 -r 552c989c1601 src/mono_opt.sml --- a/src/mono_opt.sml Thu Sep 10 14:55:27 2009 -0400 +++ b/src/mono_opt.sml Sat Sep 12 09:31:50 2009 -0400 @@ -76,11 +76,19 @@ | _ => s end -val urlifyString = String.translate (fn #" " => "+" - | ch => if Char.isAlphaNum ch then - str ch - else - "%" ^ hexIt ch) +fun urlifyString s = + case s of + "" => "_" + | _ => + (if String.sub (s, 0) = #"_" then + "_" + else + "") + ^ String.translate (fn #" " => "+" + | ch => if Char.isAlphaNum ch then + str ch + else + "%" ^ hexIt ch) s fun sqlifyInt n = #p_cast (Settings.currentDbms ()) (attrifyInt n, Settings.Int)