From 3152346712c520d71538ed4d0eacd8fd6af029c9 Mon Sep 17 00:00:00 2001 From: Sebastien Pouliot Date: Fri, 8 Oct 2010 11:54:36 -0400 Subject: [PATCH] Fix ASP.NET HttpResponse not to depend on a (fixed) bug in UriBuilder * System.Web/System.Web/HttpResponse.cs: Ensure '?' is not encoded as %3F while redirecting (e.g. aspxerrorpath) since this can cause a loop. i.e. not found leading to not found... * System/System/Test/System/UriBuilderTest.cs: Add test to confirm the right behavior of UriBuilder wrt how it was used by Mono's ASP.NET --- .../System.Web/System.Web/HttpResponse.cs | 10 +++++-- .../System/Test/System/UriBuilderTest.cs | 30 +++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) diff --git a/mcs/class/System.Web/System.Web/HttpResponse.cs b/mcs/class/System.Web/System.Web/HttpResponse.cs index 71402a1fcbe..e96db263a7f 100644 --- a/mcs/class/System.Web/System.Web/HttpResponse.cs +++ b/mcs/class/System.Web/System.Web/HttpResponse.cs @@ -880,10 +880,16 @@ namespace System.Web HttpRuntimeSection config = WebConfigurationManager.GetWebApplicationSection ("system.web/httpRuntime") as HttpRuntimeSection; if (config != null && config.UseFullyQualifiedRedirectUrl) { var ub = new UriBuilder (context.Request.Url); - ub.Path = url; + int qpos = url.IndexOf ('?'); + if (qpos == -1) { + ub.Path = url; + ub.Query = null; + } else { + ub.Path = url.Substring (0, qpos); + ub.Query = url.Substring (qpos + 1); + } ub.Fragment = null; ub.Password = null; - ub.Query = null; ub.UserName = null; url = ub.Uri.ToString (); } diff --git a/mcs/class/System/Test/System/UriBuilderTest.cs b/mcs/class/System/Test/System/UriBuilderTest.cs index 9f9266d232e..bf341af8613 100644 --- a/mcs/class/System/Test/System/UriBuilderTest.cs +++ b/mcs/class/System/Test/System/UriBuilderTest.cs @@ -343,6 +343,36 @@ namespace MonoTests.System Assert.AreEqual (80, ub.Port, "2.Port"); Assert.AreEqual ("/dir/subdir/file", ub.Path, "2.Path"); } + + [Test] + public void AspNetRedirectUsage_Old () + { + Uri uri = new Uri ("http://192.168.0.21:80/WebResource.axd?d=AAAAAAAAAAEAAAAAAAAAAA2"); + UriBuilder ub = new UriBuilder (uri); + ub.Path = "error404.aspx?aspxerrorpath=/WebResource.axd"; + ub.Fragment = null; + ub.Password = null; + ub.Query = null; + ub.UserName = null; + // a bug in older UriBuilder did not encode the ? - existing ASP.NET depends on buggy behavior + Assert.AreEqual ("http://192.168.0.21/error404.aspx%3Faspxerrorpath=/WebResource.axd", ub.Uri.ToString ()); + } + + [Test] + public void AspNetRedirectUsage_New () + { + string path = "error404.aspx?aspxerrorpath=/WebResource.axd"; + Uri uri = new Uri ("http://192.168.0.21:80/WebResource.axd?d=AAAAAAAAAAEAAAAAAAAAAA2"); + UriBuilder ub = new UriBuilder (uri); + int qpos = path.IndexOf ('?'); + ub.Path = path.Substring (0, qpos); + ub.Fragment = null; + ub.Password = null; + ub.Query = path.Substring (qpos + 1); + ub.UserName = null; + // this is what ASP.NET really means (the ?) + Assert.AreEqual ("http://192.168.0.21/error404.aspx?aspxerrorpath=/WebResource.axd", ub.Uri.ToString ()); + } } } -- GitLab