Merge branch 'merge/release/2.2-to-master'

This commit is contained in:
Kiran Challa 2018-07-13 10:58:23 -07:00
commit bbf1b8ff85
2 changed files with 68 additions and 2 deletions

View File

@ -375,7 +375,13 @@ namespace Microsoft.AspNetCore.Routing.Template
var sa = a as string;
var sb = b as string;
if (sa != null && sb != null)
// In case of strings, consider empty and null the same.
// Since null cannot tell us the type, consider it to be a string if the other value is a string.
if ((sa == string.Empty && sb == null) || (sb == string.Empty && sa == null))
{
return true;
}
else if (sa != null && sb != null)
{
// For strings do a case-insensitive comparison
return string.Equals(sa, sb, StringComparison.OrdinalIgnoreCase);

View File

@ -708,7 +708,7 @@ namespace Microsoft.AspNetCore.Routing.Template.Tests
}
[Fact]
public void TemplateBinder_KeepsExplicitlySuppliedRouteValues_OnFailedRouetMatch()
public void TemplateBinder_KeepsExplicitlySuppliedRouteValues_OnFailedRouteMatch()
{
// Arrange
var template = "{area?}/{controller=Home}/{action=Index}/{id?}";
@ -1211,6 +1211,8 @@ namespace Microsoft.AspNetCore.Routing.Template.Tests
[Theory]
[InlineData(null, null, true)]
[InlineData("", null, true)]
[InlineData(null, "", true)]
[InlineData("blog", null, false)]
[InlineData(null, "store", false)]
[InlineData("Cool", "cool", true)]
@ -1228,6 +1230,64 @@ namespace Microsoft.AspNetCore.Routing.Template.Tests
}
}
[Fact]
public void GetValues_SuccessfullyMatchesRouteValues_ForExplicitEmptyStringValue_AndNullDefault()
{
// Arrange
var expected = "/Home/Index";
var template = "Home/Index";
var defaults = new RouteValueDictionary(new { controller = "Home", action = "Index", area = (string)null });
var ambientValues = new RouteValueDictionary(new { controller = "Rail", action = "Schedule", area = "Travel" });
var explicitValues = new RouteValueDictionary(new { controller = "Home", action = "Index", area = "" });
var binder = new TemplateBinder(
UrlEncoder.Default,
new DefaultObjectPoolProvider().Create(new UriBuilderContextPooledObjectPolicy()),
TemplateParser.Parse(template),
defaults);
// Act1
var result = binder.GetValues(ambientValues, explicitValues);
// Assert1
Assert.NotNull(result);
// Act2
var boundTemplate = binder.BindValues(result.AcceptedValues);
// Assert2
Assert.NotNull(boundTemplate);
Assert.Equal(expected, boundTemplate);
}
[Fact]
public void GetValues_SuccessfullyMatchesRouteValues_ForExplicitNullValue_AndEmptyStringDefault()
{
// Arrange
var expected = "/Home/Index";
var template = "Home/Index";
var defaults = new RouteValueDictionary(new { controller = "Home", action = "Index", area = "" });
var ambientValues = new RouteValueDictionary(new { controller = "Rail", action = "Schedule", area = "Travel" });
var explicitValues = new RouteValueDictionary(new { controller = "Home", action = "Index", area = (string)null });
var binder = new TemplateBinder(
UrlEncoder.Default,
new DefaultObjectPoolProvider().Create(new UriBuilderContextPooledObjectPolicy()),
TemplateParser.Parse(template),
defaults);
// Act1
var result = binder.GetValues(ambientValues, explicitValues);
// Assert1
Assert.NotNull(result);
// Act2
var boundTemplate = binder.BindValues(result.AcceptedValues);
// Assert2
Assert.NotNull(boundTemplate);
Assert.Equal(expected, boundTemplate);
}
private static IInlineConstraintResolver GetInlineConstraintResolver()
{
var services = new ServiceCollection().AddOptions();