Sort endpoint pattern with OrdinalIgnoreCase (#6059)

This commit is contained in:
James Newton-King 2018-12-21 10:47:37 +13:00 committed by GitHub
parent dbf1dca723
commit 28cf059a3d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 4 deletions

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
@ -61,7 +61,7 @@ namespace Microsoft.AspNetCore.Routing.Matching
{ {
if (routeEndpointY != null) if (routeEndpointY != null)
{ {
return routeEndpointX.RoutePattern.RawText.CompareTo(routeEndpointY.RoutePattern.RawText); return string.Compare(routeEndpointX.RoutePattern.RawText, routeEndpointY.RoutePattern.RawText, StringComparison.OrdinalIgnoreCase);
} }
return 1; return 1;

View File

@ -1,4 +1,4 @@
// Copyright (c) .NET Foundation. All rights reserved. // Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System.Collections.Generic; using System.Collections.Generic;
@ -87,7 +87,7 @@ namespace Microsoft.AspNetCore.Routing.Matching
var result = comparer.Compare(endpoint1, endpoint2); var result = comparer.Compare(endpoint1, endpoint2);
// Assert // Assert
Assert.Equal(1, result); Assert.True(result > 0);
} }
[Fact] [Fact]
@ -218,6 +218,29 @@ namespace Microsoft.AspNetCore.Routing.Matching
e => Assert.Same(endpoint7, e)); e => Assert.Same(endpoint7, e));
} }
[Fact]
public void Compare_PatternOrder_OrdinalIgnoreCaseSort()
{
// Arrange
var endpoint1 = CreateEndpoint("/I", order: 0);
var endpoint2 = CreateEndpoint("/i", order: 0);
var endpoint3 = CreateEndpoint("/\u0131", order: 0); // Turkish lowercase i
var list = new List<RouteEndpoint>() { endpoint1, endpoint2, endpoint3 };
var comparer = CreateComparer();
// Act
list.Sort(comparer);
// Assert
Assert.Collection(
list,
e => Assert.Same(endpoint1, e),
e => Assert.Same(endpoint2, e),
e => Assert.Same(endpoint3, e));
}
private static RouteEndpoint CreateEndpoint(string template, int order, params object[] metadata) private static RouteEndpoint CreateEndpoint(string template, int order, params object[] metadata)
{ {
return new RouteEndpoint( return new RouteEndpoint(