[Mono-dev] UrlEncode difference in dotnet and mono
Andrew Skiba
andrews at mainsoft.com
Tue Jan 3 07:03:19 EST 2006
Hi Ben,
Sorry for late answer.
I have problems with Mono System.Web at my cygwin, so if there is anyone
still interested in solving the problem, I attach the unittest and the
fix here, please check they are correct. The unittest is based on the
test I made successfully on dotnet and Grasshopper after applying the
patch.
Regards, Andrew.
Index: System.Web/HttpUtility.cs
===================================================================
--- System.Web/HttpUtility.cs (revision 55002)
+++ System.Web/HttpUtility.cs (working copy)
@@ -650,7 +650,7 @@
int end = offset + count;
for (int i = offset; i < end; i++) {
char c = (char) bytes [i];
- if ((c == ' ') || (c < '0' && c != '-'
&& c != '.') ||
+ if ((c == ' ') || (c < '0' && c != '-'
&& c != '.' && c != '*') ||
(c < 'A' && c > '9') ||
(c > 'Z' && c < 'a' && c != '_') ||
(c > 'z')) {
Index: Test/System.Web/HttpUtilityTest.cs
===================================================================
--- Test/System.Web/HttpUtilityTest.cs (revision 55002)
+++ Test/System.Web/HttpUtilityTest.cs (working copy)
@@ -131,6 +131,21 @@
Assert.AreEqual ("%7f",
HttpUtility.UrlEncodeUnicode ("" + (char) 127), "#4");
Assert.AreEqual ("%u0080",
HttpUtility.UrlEncodeUnicode ("" + (char) 128), "#5");
}
+
+ [Test]
+ public void UrlEncode ()
+ {
+ string expected =
"%00%01%02%03%04%05%06%07%08%09%0a%0b%0c%0d%0e%0f%10%11%12%13%14%15%16%1
7%18%19%1a%1b%1c%1d%1e%1f+!%22%23%24%25%26'()*%2b%2c-.%2f0123456789%3a%3
b%3c%3d%3e%3f%40ABCDEFGHIJKLMNOPQRSTUVWXYZ%5b%5c%5d%5e_%60abcdefghijklmn
opqrstuvwxyz%7b%7c%7d%7e%7f";
+ StringBuilder sb = new StringBuilder ();
+ for (char c=Char.MinValue; c<128; c++)
+ sb.Append
(System.Web.HttpUtility.UrlEncode(c.ToString()));
+ Assert.AreEqual (expected, sb.ToString ());
+ for (char c=(char)128; c < Char.MaxValue; c++) {
+ string s = c.ToString();
+ Assert.IsTrue (s !=
System.Web.HttpUtility.UrlEncode(s),
+ "UrlEncode must escape character
'"+s+"'");
+ }
+ }
}
}
> -----Original Message-----
> From: Ben Maurer [mailto:bmaurer at ximian.com]
> Sent: Thursday, December 22, 2005 01:14
> To: Andrew Skiba
> Cc: gonzalo at ximian.com; Mono-devel-list at lists.ximian.com
> Subject: Re: [Mono-dev] UrlEncode difference in dotnet and mono
>
> > Hi Gonzalo,
> >
> > I found that UrlEncode behaves differently in dotnet and
> Mono, namely
> > Mono encodes the asterisk (*) symbol into %2a.
> >
> > The following code prints different values, for example:
> >
> > public static void Main ()
> > {
> > Console.Out.WriteLine
> > (System.Web.HttpUtility.UrlEncode("aaa*bbb"));
> > }
> >
> > A naive fix might be like this, but may be there are
> similar problems
> > with other characters. What do you think?
>
> This should really come with a unit test. In fact, what
> really should be done is to generaate a table of UrlEncode
> (c) for c in [0...char.MaxValue] on msft and check that we
> give the same results. This would make sure we have no other issues.
>
> -- Ben
>
>
>
More information about the Mono-devel-list
mailing list