提交 31523467 编写于 作者: S Sebastien Pouliot

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
上级 7912621a
...@@ -880,10 +880,16 @@ namespace System.Web ...@@ -880,10 +880,16 @@ namespace System.Web
HttpRuntimeSection config = WebConfigurationManager.GetWebApplicationSection ("system.web/httpRuntime") as HttpRuntimeSection; HttpRuntimeSection config = WebConfigurationManager.GetWebApplicationSection ("system.web/httpRuntime") as HttpRuntimeSection;
if (config != null && config.UseFullyQualifiedRedirectUrl) { if (config != null && config.UseFullyQualifiedRedirectUrl) {
var ub = new UriBuilder (context.Request.Url); 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.Fragment = null;
ub.Password = null; ub.Password = null;
ub.Query = null;
ub.UserName = null; ub.UserName = null;
url = ub.Uri.ToString (); url = ub.Uri.ToString ();
} }
......
...@@ -343,6 +343,36 @@ namespace MonoTests.System ...@@ -343,6 +343,36 @@ namespace MonoTests.System
Assert.AreEqual (80, ub.Port, "2.Port"); Assert.AreEqual (80, ub.Port, "2.Port");
Assert.AreEqual ("/dir/subdir/file", ub.Path, "2.Path"); 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 ());
}
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册