Use string.IsNullOrEmpty instead of string.IsNullOrWhitespace
Fixes #3593
This commit is contained in:
parent
490fcf1ab4
commit
c5346f7bf9
|
|
@ -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)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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++)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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 };
|
||||
|
|
|
|||
|
|
@ -183,7 +183,7 @@ namespace System.Net.Http
|
|||
/// <returns>Unquoted token.</returns>
|
||||
public static string UnquoteToken(string token)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(token))
|
||||
if (string.IsNullOrEmpty(token))
|
||||
{
|
||||
return token;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue