[Mono-dev] [PATCH] Improve System.Net.WebClient's CreateUri(Uri address) query string handling

Jon Herron jon.herron at yahoo.com
Sat Mar 20 00:08:56 EDT 2010


This patch fixes an issue I ran into when passing a Uri to WebClient's DownloadString method that contains a query string - CreateUri would re-append the query string to the end of the uri.  This makes CreateUri work similar to MakeUri.  I didn't see a great way to make a test for this, however for this sample app:

using System;
using System.Net;

public class TestWebClientBug
{
  public static void Main(string[] args)
  {
    String url = "http://localhost/?var1=ok and more text also&var2=4&var3=caribou";
    WebClient wc = new WebClient();
    Uri uri = new Uri(url);

    wc.DownloadString(url);
    wc.DownloadString(uri);
  }
}

In my access logs with mono 2.6.1 I see:

127.0.0.1 - - [19/Mar/2010:19:50:11 -0400] "GET /?var1=ok%20and%20more%20text%20also&var2=4&var3=caribou HTTP/1.1" 200 3662
127.0.0.1 - - [19/Mar/2010:19:50:11 -0400] "GET /?var1=ok and more text also&var2=4&var3=caribou?var1=ok%20and%20more%20text%20also&var2=4&var3=caribou HTTP/1.1" 200 3662

With this patch applied to trunk:

127.0.0.1 - - [19/Mar/2010:19:50:33 -0400] "GET /?var1=ok%20and%20more%20text%20also&var2=4&var3=caribou HTTP/1.1" 200 3662
127.0.0.1 - - [19/Mar/2010:19:50:33 -0400] "GET /?var1=ok%20and%20more%20text%20also&var2=4&var3=caribou HTTP/1.1" 200 3662

Also I think bug #577815 is fixed in 2.6.1, or at least the url that I tested with did not get truncated on the first space.

https://bugzilla.novell.com/show_bug.cgi?id=577815

***** Diff *****

Index: ChangeLog
===================================================================
--- ChangeLog    (revision 153929)
+++ ChangeLog    (working copy)
@@ -35,6 +35,11 @@
     * WebResponse.cs: Internal type for Moonlight. Removed unneeded
     NET_2_0 defines
 
+2010-03-19 Jon Herron <jon.herron at yahoo.com>
+
+    * WebClient.cs: when CreateUri is called with a Uri parameter 
+    that contains a query string do not append the query string again.
+
 2010-03-18 Gonzalo Paniagua Javier <gonzalo at novell.com>
 
     * FtpWebResponse.cs:
Index: WebClient.cs
===================================================================
--- WebClient.cs    (revision 153929)
+++ WebClient.cs    (working copy)
@@ -871,9 +871,7 @@
 #if NET_2_0
         Uri CreateUri (Uri address)
         {
-            string query = address.Query;
-            if (String.IsNullOrEmpty (query))
-                query = GetQueryString (true);
+            string query = GetQueryString (true);
 
             if (baseAddress == null && query == null)
                 return address;




      


More information about the Mono-devel-list mailing list