diff --git a/src/Microsoft.AspNet.Mvc.Core/Formatters/InputFormatter.cs b/src/Microsoft.AspNet.Mvc.Core/Formatters/InputFormatter.cs index 483ef03851..a6fd215ef0 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Formatters/InputFormatter.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Formatters/InputFormatter.cs @@ -123,7 +123,7 @@ namespace Microsoft.AspNet.Mvc.Formatters if (contentType != null) { var charset = contentType.Charset; - if (!string.IsNullOrWhiteSpace(charset)) + if (!string.IsNullOrEmpty(charset)) { foreach (var supportedEncoding in SupportedEncodings) { diff --git a/src/Microsoft.AspNet.Mvc.Core/Formatters/OutputFormatter.cs b/src/Microsoft.AspNet.Mvc.Core/Formatters/OutputFormatter.cs index 9a980455ad..7863a8a498 100644 --- a/src/Microsoft.AspNet.Mvc.Core/Formatters/OutputFormatter.cs +++ b/src/Microsoft.AspNet.Mvc.Core/Formatters/OutputFormatter.cs @@ -254,7 +254,7 @@ namespace Microsoft.AspNet.Mvc.Formatters for (var i = 0; i < acceptValues.Count; i++) { var charset = acceptValues[i].Value; - if (!string.IsNullOrWhiteSpace(charset)) + if (!string.IsNullOrEmpty(charset)) { for (var j = 0; j < SupportedEncodings.Count; j++) { diff --git a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/SimpleTypeModelBinder.cs b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/SimpleTypeModelBinder.cs index 4963002370..7747433b2e 100644 --- a/src/Microsoft.AspNet.Mvc.Core/ModelBinding/SimpleTypeModelBinder.cs +++ b/src/Microsoft.AspNet.Mvc.Core/ModelBinding/SimpleTypeModelBinder.cs @@ -37,7 +37,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding { var modelAsString = model as string; if (bindingContext.ModelMetadata.ConvertEmptyStringToNull && - string.IsNullOrWhiteSpace(modelAsString)) + string.IsNullOrEmpty(modelAsString)) { model = null; } diff --git a/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/AttributeMatcher.cs b/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/AttributeMatcher.cs index 60469457f7..2d88203dcb 100644 --- a/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/AttributeMatcher.cs +++ b/src/Microsoft.AspNet.Mvc.TagHelpers/Internal/AttributeMatcher.cs @@ -100,19 +100,24 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal // Perf: Avoid allocating enumerator for (var i = 0; i < requiredAttributes.Length; i++) { - var attribute = requiredAttributes[i]; - if (!context.AllAttributes.ContainsName(attribute) || - context.AllAttributes[attribute] == null || - (context.AllAttributes[attribute].Value is string && - string.IsNullOrWhiteSpace(context.AllAttributes[attribute].Value as string))) + var requiredAttribute = requiredAttributes[i]; + IReadOnlyTagHelperAttribute attribute; + if (!context.AllAttributes.TryGetAttribute(requiredAttribute, out attribute)) { - // Missing attribute! - missingAttributes.Add(attribute); + // Missing attribute. + missingAttributes.Add(requiredAttribute); + continue; } - else + + var valueAsString = attribute.Value as string; + if (valueAsString != null && string.IsNullOrEmpty(valueAsString)) { - presentAttributes.Add(attribute); + // Treat attributes with empty values as missing. + missingAttributes.Add(requiredAttribute); + continue; } + + presentAttributes.Add(requiredAttribute); } return new PresentMissingAttributes { Present = presentAttributes, Missing = missingAttributes }; diff --git a/src/Microsoft.AspNet.Mvc.WebApiCompatShim/ContentNegotiator/FormattingUtilities.cs b/src/Microsoft.AspNet.Mvc.WebApiCompatShim/ContentNegotiator/FormattingUtilities.cs index 392210dd48..5e0e775f8e 100644 --- a/src/Microsoft.AspNet.Mvc.WebApiCompatShim/ContentNegotiator/FormattingUtilities.cs +++ b/src/Microsoft.AspNet.Mvc.WebApiCompatShim/ContentNegotiator/FormattingUtilities.cs @@ -183,7 +183,7 @@ namespace System.Net.Http /// Unquoted token. public static string UnquoteToken(string token) { - if (string.IsNullOrWhiteSpace(token)) + if (string.IsNullOrEmpty(token)) { return token; } diff --git a/test/Microsoft.AspNet.Mvc.IntegrationTests/SimpleTypeModelBinderIntegrationTest.cs b/test/Microsoft.AspNet.Mvc.IntegrationTests/SimpleTypeModelBinderIntegrationTest.cs index 996199d354..a3d76f0fd6 100644 --- a/test/Microsoft.AspNet.Mvc.IntegrationTests/SimpleTypeModelBinderIntegrationTest.cs +++ b/test/Microsoft.AspNet.Mvc.IntegrationTests/SimpleTypeModelBinderIntegrationTest.cs @@ -271,7 +271,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests }; var operationContext = ModelBindingTestHelper.GetOperationBindingContext(request => { - request.QueryString = QueryString.Create("Parameter1", " "); + request.QueryString = QueryString.Create("Parameter1", ""); }); var modelState = operationContext.ActionContext.ModelState; @@ -290,10 +290,10 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests Assert.False(modelState.IsValid); var key = Assert.Single(modelState.Keys); Assert.Equal("Parameter1", key); - Assert.Equal(" ", modelState[key].AttemptedValue); - Assert.Equal(" ", modelState[key].RawValue); + Assert.Equal("", modelState[key].AttemptedValue); + Assert.Equal("", modelState[key].RawValue); var error = Assert.Single(modelState[key].Errors); - Assert.Equal("The value ' ' is invalid.", error.ErrorMessage, StringComparer.Ordinal); + Assert.Equal("The value '' is invalid.", error.ErrorMessage, StringComparer.Ordinal); Assert.Null(error.Exception); }