Skip to content

Commit 8884b90

Browse files
committed
Sort endpoint pattern with OrdinalIgnoreCase
1 parent 1ad77cf commit 8884b90

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/Http/Routing/src/Matching/EndpointComparer.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
@@ -61,7 +61,7 @@ private int ComparePattern(Endpoint x, Endpoint y)
6161
{
6262
if (routeEndpointY != null)
6363
{
64-
return routeEndpointX.RoutePattern.RawText.CompareTo(routeEndpointY.RoutePattern.RawText);
64+
return string.Compare(routeEndpointX.RoutePattern.RawText, routeEndpointY.RoutePattern.RawText, StringComparison.OrdinalIgnoreCase);
6565
}
6666

6767
return 1;

src/Http/Routing/test/UnitTests/Matching/RouteEndpointComparerTest.cs renamed to src/Http/Routing/test/UnitTests/Matching/EndpointComparerTest.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) .NET Foundation. All rights reserved.
1+
// Copyright (c) .NET Foundation. All rights reserved.
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System.Collections.Generic;
@@ -87,7 +87,7 @@ public void Compare_PrefersTemplate_IfOtherCriteriaIsSame()
8787
var result = comparer.Compare(endpoint1, endpoint2);
8888

8989
// Assert
90-
Assert.Equal(1, result);
90+
Assert.True(result > 0);
9191
}
9292

9393
[Fact]
@@ -218,6 +218,29 @@ public void Sort_MoreSpecific_FirstInList()
218218
e => Assert.Same(endpoint7, e));
219219
}
220220

221+
[Fact]
222+
public void Compare_PatternOrder_OrdinalIgnoreCaseSort()
223+
{
224+
// Arrange
225+
var endpoint1 = CreateEndpoint("/I", order: 0);
226+
var endpoint2 = CreateEndpoint("/i", order: 0);
227+
var endpoint3 = CreateEndpoint("/\u0131", order: 0); // Turkish lowercase i
228+
229+
var list = new List<RouteEndpoint>() { endpoint1, endpoint2, endpoint3 };
230+
231+
var comparer = CreateComparer();
232+
233+
// Act
234+
list.Sort(comparer);
235+
236+
// Assert
237+
Assert.Collection(
238+
list,
239+
e => Assert.Same(endpoint1, e),
240+
e => Assert.Same(endpoint2, e),
241+
e => Assert.Same(endpoint3, e));
242+
}
243+
221244
private static RouteEndpoint CreateEndpoint(string template, int order, params object[] metadata)
222245
{
223246
return new RouteEndpoint(

0 commit comments

Comments
 (0)