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

Gonzalo Paniagua Javier gonzalo.mono at gmail.com
Sun Mar 21 14:11:12 EDT 2010


I have checked in a fix in trunk:
http://lists.ximian.com/pipermail/mono-patches/2010-March/168726.html

It should fix the issues you are reporting. If you need this fix in the
2.6/2.4 branches, feel free to backport it.

Thanks.

-Gonzalo

On Sat, 2010-03-20 at 20:50 -0700, Jon Herron wrote:
> With my patch calling DownloadString with either a string or Uri fails the same way under the scenario you describe, where as before they failed in different ways.  With the updated test:
> 
> using System;
> using System.Collections.Specialized;
> using System.Net;
> 
> public class TestWebClientBug
> {
>   public static void Main(string[] args)
>   {
>     NameValueCollection qs = new NameValueCollection();
>     String url = "http://localhost/?var1=ok and more text also&var2=4&var3=caribou";
>     WebClient wc = new WebClient();
>     Uri uri = new Uri(url);
> 
>     qs.Add("qs_a", "1");
>     qs.Add("qs_b", "some var");
>     qs.Add("qs_c", "another");
> 
>     wc.QueryString = qs;
> 
>     wc.DownloadString(url);
>     wc.DownloadString(uri);
> 
>     Console.WriteLine(uri.IsAbsoluteUri);
>     Console.WriteLine(uri.Query);
>     Console.WriteLine(uri.ToString());
>   }
> }
> 
> 2.6.1 yields:
> 
> 127.0.0.1 - - [20/Mar/2010:19:03:39 -0400] "GET /?var1=ok and more text also&var2=4&var3=caribou?qs_a=1&qs_b=some+var&qs_c=another HTTP/1.1" 200 3662
> 127.0.0.1 - - [20/Mar/2010:19:03:39 -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
> 
> And trunk with my patch yields:
> 
> 127.0.0.1 - - [20/Mar/2010:19:04:03 -0400] "GET /?var1=ok and more text also&var2=4&var3=caribou?qs_a=1&qs_b=some+var&qs_c=another HTTP/1.1" 200 3662
> 127.0.0.1 - - [20/Mar/2010:19:04:03 -0400] "GET /?var1=ok and more text also&var2=4&var3=caribou?qs_a=1&qs_b=some+var&qs_c=another HTTP/1.1" 200 3662
> 
> Granted the second question mark is a problem, but it is consistent - however one could argue a new bug is worse than an existing bug I suppose.  
> 
> I'll look at fixing the issue you describe as well, looks like it will need to be fixed for calling the CreateUri with a string or Uri.  Is it safe to assume that the patch won't get committed until this issue is resolved?
> 
> Jon
> 
> 
> --- On Sat, 3/20/10, Gonzalo Paniagua Javier <gonzalo.mono at gmail.com> wrote:
> 
> > From: Gonzalo Paniagua Javier <gonzalo.mono at gmail.com>
> > Subject: Re: [Mono-dev] [PATCH] Improve System.Net.WebClient's CreateUri(Uri address) query string handling
> > To: mono-devel-list at lists.ximian.com
> > Date: Saturday, March 20, 2010, 4:35 AM
> > On Fri, 2010-03-19 at 21:08 -0700,
> > Jon Herron wrote:
> > > 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
> > 
> > I'm afraid your patch might be hiding another issue: can
> > you try your
> > URL + setting some values in wc.QueryString? What the
> > resulting url in
> > that case?
> > 
> > -Gonzalo
> > 
> > 
> > _______________________________________________
> > Mono-devel-list mailing list
> > Mono-devel-list at lists.ximian.com
> > http://lists.ximian.com/mailman/listinfo/mono-devel-list
> > 
> 
> 
>       




More information about the Mono-devel-list mailing list