Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Commit 54579f9

Browse files
authored
Merge pull request #8673 from dotnet-maestro-bot/merge/release/2.2-to-master
[automated] Merge branch 'release/2.2' => 'master'
2 parents 16b15fc + 579341c commit 54579f9

File tree

31 files changed

+620
-73
lines changed

31 files changed

+620
-73
lines changed

benchmarks/Microsoft.AspNetCore.Mvc.Performance/ActionSelectorBenchmark.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Globalization;
67
using System.Linq;
78
using System.Threading.Tasks;
89
using BenchmarkDotNet.Attributes;
@@ -123,8 +124,8 @@ private static IReadOnlyList<ActionDescriptor> NaiveSelectCandidates(ActionDescr
123124
var isMatch = true;
124125
foreach (var kvp in action.RouteValues)
125126
{
126-
var routeValue = Convert.ToString(routeValues[kvp.Key]) ?? string.Empty;
127-
127+
var routeValue = Convert.ToString(routeValues[kvp.Key], CultureInfo.InvariantCulture) ??
128+
string.Empty;
128129
if (string.IsNullOrEmpty(kvp.Value) && string.IsNullOrEmpty(routeValue))
129130
{
130131
// Match
@@ -156,7 +157,7 @@ private static ActionDescriptor CreateActionDescriptor(object obj)
156157
var routeValues = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
157158
foreach (var kvp in new RouteValueDictionary(obj))
158159
{
159-
routeValues.Add(kvp.Key, Convert.ToString(kvp.Value) ?? string.Empty);
160+
routeValues.Add(kvp.Key, Convert.ToString(kvp.Value, CultureInfo.InvariantCulture) ?? string.Empty);
160161
}
161162

162163
return new ActionDescriptor()

src/Microsoft.AspNetCore.Mvc.Core/ApplicationModels/InferParameterBindingInfoConvention.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,10 @@ public void Apply(ControllerModel controller)
5959

6060
internal void InferParameterBindingSources(ActionModel action)
6161
{
62-
var inferredBindingSources = new BindingSource[action.Parameters.Count];
62+
if (SuppressInferBindingSourcesForParameters)
63+
{
64+
return;
65+
}
6366

6467
for (var i = 0; i < action.Parameters.Count; i++)
6568
{

src/Microsoft.AspNetCore.Mvc.Core/Formatters/FormatFilter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5+
using System.Globalization;
56
using System.Linq;
67
using Microsoft.AspNetCore.Mvc.ApiExplorer;
78
using Microsoft.AspNetCore.Mvc.Filters;
@@ -59,7 +60,7 @@ public virtual string GetFormat(ActionContext context)
5960
if (context.RouteData.Values.TryGetValue("format", out var obj))
6061
{
6162
// null and string.Empty are equivalent for route values.
62-
var routeValue = obj?.ToString();
63+
var routeValue = Convert.ToString(obj, CultureInfo.InvariantCulture);
6364
return string.IsNullOrEmpty(routeValue) ? null : routeValue;
6465
}
6566

@@ -166,8 +167,7 @@ public void OnResultExecuting(ResultExecutingContext context)
166167
return;
167168
}
168169

169-
var objectResult = context.Result as ObjectResult;
170-
if (objectResult == null)
170+
if (!(context.Result is ObjectResult objectResult))
171171
{
172172
return;
173173
}

src/Microsoft.AspNetCore.Mvc.Core/Internal/ActionSelector.cs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Diagnostics;
7+
using System.Globalization;
78
using System.Linq;
89
using System.Threading;
910
using Microsoft.AspNetCore.Mvc.Abstractions;
@@ -81,11 +82,10 @@ public IReadOnlyList<ActionDescriptor> SelectCandidates(RouteContext context)
8182
var values = new string[keys.Length];
8283
for (var i = 0; i < keys.Length; i++)
8384
{
84-
context.RouteData.Values.TryGetValue(keys[i], out object value);
85-
85+
context.RouteData.Values.TryGetValue(keys[i], out var value);
8686
if (value != null)
8787
{
88-
values[i] = value as string ?? Convert.ToString(value);
88+
values[i] = value as string ?? Convert.ToString(value, CultureInfo.InvariantCulture);
8989
}
9090
}
9191

@@ -220,9 +220,11 @@ private IReadOnlyList<ActionSelectorCandidate> EvaluateActionConstraintsCore(
220220
var actionsWithConstraint = new List<ActionSelectorCandidate>();
221221
var actionsWithoutConstraint = new List<ActionSelectorCandidate>();
222222

223-
var constraintContext = new ActionConstraintContext();
224-
constraintContext.Candidates = candidates;
225-
constraintContext.RouteContext = context;
223+
var constraintContext = new ActionConstraintContext
224+
{
225+
Candidates = candidates,
226+
RouteContext = context
227+
};
226228

227229
// Perf: Avoid allocations
228230
for (var i = 0; i < candidates.Count; i++)
@@ -294,7 +296,7 @@ private IReadOnlyList<ActionSelectorCandidate> EvaluateActionConstraintsCore(
294296
// canonical entries. When you don't hit a case-sensitive match it will try the case-insensitive dictionary
295297
// so you still get correct behaviors.
296298
//
297-
// The difference here is because while MVC is case-insensitive, doing a case-sensitive comparison is much
299+
// The difference here is because while MVC is case-insensitive, doing a case-sensitive comparison is much
298300
// faster. We also expect that most of the URLs we process are canonically-cased because they were generated
299301
// by Url.Action or another routing api.
300302
//
@@ -316,7 +318,7 @@ public Cache(ActionDescriptorCollection actions)
316318
OrdinalEntries = new Dictionary<string[], List<ActionDescriptor>>(StringArrayComparer.Ordinal);
317319
OrdinalIgnoreCaseEntries = new Dictionary<string[], List<ActionDescriptor>>(StringArrayComparer.OrdinalIgnoreCase);
318320

319-
// We need to first identify of the keys that action selection will look at (in route data).
321+
// We need to first identify of the keys that action selection will look at (in route data).
320322
// We want to only consider conventionally routed actions here.
321323
var routeKeys = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
322324
for (var i = 0; i < actions.Items.Count; i++)

src/Microsoft.AspNetCore.Mvc.Core/Internal/NormalizedRouteValue.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33

44
using System;
5+
using System.Globalization;
56

67
namespace Microsoft.AspNetCore.Mvc.Internal
78
{
@@ -45,7 +46,7 @@ public static string GetNormalizedRouteValue(ActionContext context, string key)
4546
normalizedValue = value;
4647
}
4748

48-
var stringRouteValue = routeValue?.ToString();
49+
var stringRouteValue = Convert.ToString(routeValue, CultureInfo.InvariantCulture);
4950
if (string.Equals(normalizedValue, stringRouteValue, StringComparison.OrdinalIgnoreCase))
5051
{
5152
return normalizedValue;

src/Microsoft.AspNetCore.Mvc.Core/ModelBinding/RouteValueProvider.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,9 @@ public override ValueProviderResult GetValue(string key)
8888
throw new ArgumentNullException(nameof(key));
8989
}
9090

91-
object value;
92-
if (_values.TryGetValue(key, out value))
91+
if (_values.TryGetValue(key, out var value))
9392
{
94-
var stringValue = value as string ?? value?.ToString() ?? string.Empty;
93+
var stringValue = value as string ?? Convert.ToString(value, Culture) ?? string.Empty;
9594
return new ValueProviderResult(stringValue, Culture);
9695
}
9796
else

src/Microsoft.AspNetCore.Mvc.Core/Routing/KnownRouteValueConstraint.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
using System;
55
using System.Collections.Generic;
6+
using System.Globalization;
67
using System.Linq;
78
using Microsoft.AspNetCore.Http;
89
using Microsoft.AspNetCore.Mvc.Core;
@@ -51,10 +52,9 @@ public bool Match(
5152
throw new ArgumentNullException(nameof(values));
5253
}
5354

54-
object obj;
55-
if (values.TryGetValue(routeKey, out obj))
55+
if (values.TryGetValue(routeKey, out var obj))
5656
{
57-
var value = obj as string;
57+
var value = Convert.ToString(obj, CultureInfo.InvariantCulture);
5858
if (value != null)
5959
{
6060
var actionDescriptors = GetAndValidateActionDescriptors(httpContext);

src/Microsoft.AspNetCore.Mvc.Core/Routing/PageLinkGeneratorExtensions.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// 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

4+
using System;
45
using Microsoft.AspNetCore.Http;
56
using Microsoft.AspNetCore.Http.Features;
67
using Microsoft.AspNetCore.Mvc.Routing;
7-
using System;
88

99
namespace Microsoft.AspNetCore.Routing
1010
{
@@ -104,7 +104,7 @@ public static string GetPathByPage(
104104
}
105105

106106
var address = CreateAddress(httpContext: null, page, handler, values);
107-
return generator.GetPathByAddress<RouteValuesAddress>(address, address.ExplicitValues, pathBase, fragment, options);
107+
return generator.GetPathByAddress(address, address.ExplicitValues, pathBase, fragment, options);
108108
}
109109

110110
/// <summary>
@@ -230,4 +230,4 @@ private static RouteValueDictionary GetAmbientValues(HttpContext httpContext)
230230
return httpContext?.Features.Get<IRouteValuesFeature>()?.RouteValues;
231231
}
232232
}
233-
}
233+
}

src/Microsoft.AspNetCore.Mvc.Core/Routing/UrlHelperBase.cs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
using System;
55
using System.Collections.Generic;
66
using System.Diagnostics;
7+
using System.Globalization;
78
using System.Text;
89
using Microsoft.AspNetCore.Http;
9-
using Microsoft.AspNetCore.Mvc;
1010
using Microsoft.AspNetCore.Mvc.Core;
1111
using Microsoft.AspNetCore.Mvc.Internal;
1212
using Microsoft.AspNetCore.Routing;
@@ -162,8 +162,8 @@ protected string GenerateUrl(string protocol, string host, string virtualPath, s
162162

163163
// Perf: In most of the common cases, GenerateUrl is called with a null protocol, host and fragment.
164164
// In such cases, we might not need to build any URL as the url generated is mostly same as the virtual path available in pathData.
165-
// For such common cases, this FastGenerateUrl method saves a string allocation per GenerateUrl call.
166-
if (TryFastGenerateUrl(protocol, host, virtualPath, fragment, out string url))
165+
// For such common cases, this FastGenerateUrl method saves a string allocation per GenerateUrl call.
166+
if (TryFastGenerateUrl(protocol, host, virtualPath, fragment, out var url))
167167
{
168168
return url;
169169
}
@@ -226,8 +226,7 @@ protected string GenerateUrl(string protocol, string host, string path)
226226
// Perf: In most of the common cases, GenerateUrl is called with a null protocol, host and fragment.
227227
// In such cases, we might not need to build any URL as the url generated is mostly same as the virtual path available in pathData.
228228
// For such common cases, this FastGenerateUrl method saves a string allocation per GenerateUrl call.
229-
string url;
230-
if (TryFastGenerateUrl(protocol, host, path, fragment: null, out url))
229+
if (TryFastGenerateUrl(protocol, host, path, fragment: null, out var url))
231230
{
232231
return url;
233232
}
@@ -350,7 +349,7 @@ private static object CalculatePageName(ActionContext context, RouteValueDiction
350349
}
351350
else if (ambientValues != null)
352351
{
353-
currentPagePath = ambientValues["page"]?.ToString();
352+
currentPagePath = Convert.ToString(ambientValues["page"], CultureInfo.InvariantCulture);
354353
}
355354
else
356355
{

src/Microsoft.AspNetCore.Mvc.RazorPages/ApplicationModels/PageRouteModel.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
using System.Collections.Generic;
66
using System.Linq;
77
using Microsoft.AspNetCore.Mvc.Abstractions;
8-
using Microsoft.AspNetCore.Mvc.RazorPages;
98
using Microsoft.AspNetCore.Routing;
109

1110
namespace Microsoft.AspNetCore.Mvc.ApplicationModels
@@ -96,7 +95,7 @@ public PageRouteModel(PageRouteModel other)
9695
public IList<SelectorModel> Selectors { get; }
9796

9897
/// <summary>
99-
/// Gets a collection of route values that must be present in the <see cref="RouteData.Values"/>
98+
/// Gets a collection of route values that must be present in the <see cref="RouteData.Values"/>
10099
/// for the corresponding page to be selected.
101100
/// </summary>
102101
/// <remarks>

0 commit comments

Comments
 (0)