Hello,

After running more tests, I've found out that on MS.NET the decoding in
HttpRequest.QueryString does _not_ depend on
HttpRequest.ContentEncoding. In fact, MS seems to be always using Latin1
here. All other standard encodings fail.

A revised patch is attached, including a NUnit test case. If no one
objects, I'll commit.

- Juraj


On Sat, 2006-05-06 at 13:47 -0400, Miguel de Icaza wrote:
> Hello Juraj,
> 
> > The attached patch makes sure that the get-parameters in QueryString are
> > url-decoded using the proper encoding (when creating the
> > NameValueCollection).
> > 
> > May I commit?
> 
> Could you provide NUnit tests for this case?
> 
> Miguel
> 
Index: System.Web/ChangeLog
===================================================================
--- System.Web/ChangeLog	(revision 60170)
+++ System.Web/ChangeLog	(working copy)
@@ -1,3 +1,9 @@
+2006-05-08 Juraj Skripsky <[EMAIL PROTECTED]>
+
+	* HttpRequest (get_QueryString): UrlDecode with "latin1"
+	(== iso-8859-1) encoding. Tests indicate that MS.NET always uses
+	this encoding here.
+
 2006-04-25 Gonzalo Paniagua Javier <[EMAIL PROTECTED]>
 
 	* HttpApplicationFactory.cs: make sure that the application start event
Index: System.Web/HttpRequest.cs
===================================================================
--- System.Web/HttpRequest.cs	(revision 60170)
+++ System.Web/HttpRequest.cs	(working copy)
@@ -951,14 +951,15 @@
 					
 					string q = query_string;
 					if (q != null && q != ""){
+						Encoding enc = Encoding.GetEncoding("latin1");
 						string [] components = q.Split ('&');
 						foreach (string kv in components){
 							int pos = kv.IndexOf ('=');
 							if (pos == -1){
-								query_string_nvc.Add (null, HttpUtility.UrlDecode (kv));
+								query_string_nvc.Add (null, HttpUtility.UrlDecode (kv, enc));
 							} else {
-								string key = HttpUtility.UrlDecode (kv.Substring (0, pos));
-								string val = HttpUtility.UrlDecode (kv.Substring (pos+1));
+								string key = HttpUtility.UrlDecode (kv.Substring (0, pos), enc);
+								string val = HttpUtility.UrlDecode (kv.Substring (pos+1), enc);
 								
 								query_string_nvc.Add (key, val);
 							}
Index: Test/System.Web/ChangeLog
===================================================================
--- Test/System.Web/ChangeLog	(revision 60170)
+++ Test/System.Web/ChangeLog	(working copy)
@@ -1,3 +1,8 @@
+2006-05-08 Juraj Skripsky <[EMAIL PROTECTED]>
+
+	* HttpRequestTest: new test for the UrlDecoding of special characters
+	(e.g. german umlauts) in QueryString.
+
 2006-04-20 Andrew Skiba <[EMAIL PROTECTED]>
 
 	* SiteMapNodeTest.cs: new tests for null reference exceptions in SiteMapNode
Index: Test/System.Web/HttpRequestTest.cs
===================================================================
--- Test/System.Web/HttpRequestTest.cs	(revision 60170)
+++ Test/System.Web/HttpRequestTest.cs	(working copy)
@@ -129,6 +129,16 @@
 			HttpRequest r = new HttpRequest ("file", url, qs);
 			string s = r.PhysicalApplicationPath;
 		}
+		
+		[Test]
+		public void Test_QueryStringDecoding()
+		{
+			string url = "http://www.gnome.org/";;
+			string qs = "umlaut=%e4";
+			
+			HttpRequest r = new HttpRequest ("file", url, qs);
+			Assert.AreEqual("\u00e4", r.QueryString["umlaut"]);
+		}
 	}
 
 	[TestFixture]
_______________________________________________
Mono-devel-list mailing list
Mono-devel-list@lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list

Reply via email to