Use string.IsNullOrEmpty instead of string.IsNullOrWhitespace

Fixes #3593
This commit is contained in:
Pranav K 2015-11-24 15:47:24 -08:00
parent 490fcf1ab4
commit c5346f7bf9
6 changed files with 22 additions and 17 deletions

View File

@ -123,7 +123,7 @@ namespace Microsoft.AspNet.Mvc.Formatters
if (contentType != null) if (contentType != null)
{ {
var charset = contentType.Charset; var charset = contentType.Charset;
if (!string.IsNullOrWhiteSpace(charset)) if (!string.IsNullOrEmpty(charset))
{ {
foreach (var supportedEncoding in SupportedEncodings) foreach (var supportedEncoding in SupportedEncodings)
{ {

View File

@ -254,7 +254,7 @@ namespace Microsoft.AspNet.Mvc.Formatters
for (var i = 0; i < acceptValues.Count; i++) for (var i = 0; i < acceptValues.Count; i++)
{ {
var charset = acceptValues[i].Value; var charset = acceptValues[i].Value;
if (!string.IsNullOrWhiteSpace(charset)) if (!string.IsNullOrEmpty(charset))
{ {
for (var j = 0; j < SupportedEncodings.Count; j++) for (var j = 0; j < SupportedEncodings.Count; j++)
{ {

View File

@ -37,7 +37,7 @@ namespace Microsoft.AspNet.Mvc.ModelBinding
{ {
var modelAsString = model as string; var modelAsString = model as string;
if (bindingContext.ModelMetadata.ConvertEmptyStringToNull && if (bindingContext.ModelMetadata.ConvertEmptyStringToNull &&
string.IsNullOrWhiteSpace(modelAsString)) string.IsNullOrEmpty(modelAsString))
{ {
model = null; model = null;
} }

View File

@ -100,19 +100,24 @@ namespace Microsoft.AspNet.Mvc.TagHelpers.Internal
// Perf: Avoid allocating enumerator // Perf: Avoid allocating enumerator
for (var i = 0; i < requiredAttributes.Length; i++) for (var i = 0; i < requiredAttributes.Length; i++)
{ {
var attribute = requiredAttributes[i]; var requiredAttribute = requiredAttributes[i];
if (!context.AllAttributes.ContainsName(attribute) || IReadOnlyTagHelperAttribute attribute;
context.AllAttributes[attribute] == null || if (!context.AllAttributes.TryGetAttribute(requiredAttribute, out attribute))
(context.AllAttributes[attribute].Value is string &&
string.IsNullOrWhiteSpace(context.AllAttributes[attribute].Value as string)))
{ {
// Missing attribute! // Missing attribute.
missingAttributes.Add(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 }; return new PresentMissingAttributes { Present = presentAttributes, Missing = missingAttributes };

View File

@ -183,7 +183,7 @@ namespace System.Net.Http
/// <returns>Unquoted token.</returns> /// <returns>Unquoted token.</returns>
public static string UnquoteToken(string token) public static string UnquoteToken(string token)
{ {
if (string.IsNullOrWhiteSpace(token)) if (string.IsNullOrEmpty(token))
{ {
return token; return token;
} }

View File

@ -271,7 +271,7 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
}; };
var operationContext = ModelBindingTestHelper.GetOperationBindingContext(request => var operationContext = ModelBindingTestHelper.GetOperationBindingContext(request =>
{ {
request.QueryString = QueryString.Create("Parameter1", " "); request.QueryString = QueryString.Create("Parameter1", "");
}); });
var modelState = operationContext.ActionContext.ModelState; var modelState = operationContext.ActionContext.ModelState;
@ -290,10 +290,10 @@ namespace Microsoft.AspNet.Mvc.IntegrationTests
Assert.False(modelState.IsValid); Assert.False(modelState.IsValid);
var key = Assert.Single(modelState.Keys); var key = Assert.Single(modelState.Keys);
Assert.Equal("Parameter1", key); Assert.Equal("Parameter1", key);
Assert.Equal(" ", modelState[key].AttemptedValue); Assert.Equal("", modelState[key].AttemptedValue);
Assert.Equal(" ", modelState[key].RawValue); Assert.Equal("", modelState[key].RawValue);
var error = Assert.Single(modelState[key].Errors); 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); Assert.Null(error.Exception);
} }