diff options
author | Miguel de Icaza <miguel@gnome.org> | 2013-02-10 02:21:58 +0400 |
---|---|---|
committer | Miguel de Icaza <miguel@gnome.org> | 2013-02-10 02:21:58 +0400 |
commit | 73277ab4afd9821e52f44a938de18184ba4bf467 (patch) | |
tree | 9c1d7708955b21ed806d60fadbf01111bd90d38e /mcs/class/Microsoft.Web.Infrastructure | |
parent | 0f8da45878349ca4f060f38a66a82d8b99709a2a (diff) | |
parent | 43451a70bffc00b959282a83115f47e63c60f077 (diff) |
Merge pull request #524 from pruiz/mvc-allowhtml-fix
Fixes xamarin-bug #8965: AllowHtmlAttribute ignored throwing exception on POST using ASP.NET mvc3
Diffstat (limited to 'mcs/class/Microsoft.Web.Infrastructure')
-rw-r--r-- | mcs/class/Microsoft.Web.Infrastructure/Microsoft.Web.Infrastructure.DynamicValidationHelper/ValidationUtility.cs | 22 |
1 files changed, 20 insertions, 2 deletions
diff --git a/mcs/class/Microsoft.Web.Infrastructure/Microsoft.Web.Infrastructure.DynamicValidationHelper/ValidationUtility.cs b/mcs/class/Microsoft.Web.Infrastructure/Microsoft.Web.Infrastructure.DynamicValidationHelper/ValidationUtility.cs index 85d6ed2abaa..2605aed28d1 100644 --- a/mcs/class/Microsoft.Web.Infrastructure/Microsoft.Web.Infrastructure.DynamicValidationHelper/ValidationUtility.cs +++ b/mcs/class/Microsoft.Web.Infrastructure/Microsoft.Web.Infrastructure.DynamicValidationHelper/ValidationUtility.cs @@ -36,6 +36,8 @@ namespace Microsoft.Web.Infrastructure.DynamicValidationHelper [EditorBrowsable (EditorBrowsableState.Never)] public static class ValidationUtility { + private const string UNVALIDATED_DATA_KEY = "__MWI_UNVALIDATED_DATA_KEY"; + [SecuritySafeCritical] public static void EnableDynamicValidation (HttpContext context) { @@ -43,6 +45,13 @@ namespace Microsoft.Web.Infrastructure.DynamicValidationHelper if (req == null) return; + // We might get called more than once.. (weird, isnt it?) + if (context.Items [UNVALIDATED_DATA_KEY] != null) + return; + + // Store unvalidated values at context so we can access them later. + context.Items [UNVALIDATED_DATA_KEY] = new object [] { req.FormUnvalidated, req.QueryStringUnvalidated }; + // Just to be safe, make sure it's on req.ValidateInput (); req.SetFormCollection (new LazyWebROCollection (RequestValidationSource.Form, req.FormUnvalidated), true); @@ -71,15 +80,24 @@ namespace Microsoft.Web.Infrastructure.DynamicValidationHelper HttpRequest req = context != null ? context.Request : null; if (req == null) return null; - return req.FormUnvalidated; + return GetUnvalidatedCollection (context, 0) ?? req.FormUnvalidated; }; queryStringGetter = () => { HttpRequest req = context != null ? context.Request : null; if (req == null) return null; - return req.QueryStringUnvalidated; + return GetUnvalidatedCollection (context, 1) ?? req.QueryStringUnvalidated; }; } + + private static NameValueCollection GetUnvalidatedCollection (HttpContext context, int offset) + { + if (context.Items [UNVALIDATED_DATA_KEY] == null) + return null; + + var data = context.Items [UNVALIDATED_DATA_KEY] as object []; + return data [offset] as NameValueCollection; + } } } |