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

Commit 293ac81

Browse files
committed
Use ordinal comparisons in ExpressionTextCache
- #6349 - C# field and property names are case-sensitive - it's not important (where this cache is used) that HTML field names are case-insenstive
1 parent 17f6b17 commit 293ac81

File tree

2 files changed

+49
-2
lines changed

2 files changed

+49
-2
lines changed

src/Microsoft.AspNetCore.Mvc.ViewFeatures/Internal/ExpressionTextCache.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public bool Equals(LambdaExpression lambdaExpression1, LambdaExpression lambdaEx
7070
return true;
7171
}
7272

73-
if (!string.Equals(memberName1, memberName2, StringComparison.OrdinalIgnoreCase))
73+
if (!string.Equals(memberName1, memberName2, StringComparison.Ordinal))
7474
{
7575
return false;
7676
}
@@ -108,7 +108,7 @@ public int GetHashCode(LambdaExpression lambdaExpression)
108108
break;
109109
}
110110

111-
hashCodeCombiner.Add(memberName, StringComparer.OrdinalIgnoreCase);
111+
hashCodeCombiner.Add(memberName, StringComparer.Ordinal);
112112
expression = memberExpression.Expression;
113113
}
114114
else

test/Microsoft.AspNetCore.Mvc.ViewFeatures.Test/Internal/ExpressionHelperTest.cs

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ public static TheoryData<Expression, string> ExpressionAndTexts
3939
(Expression<Func<TestModel, int>>)(testModel => testModel.SelectedCategory.CategoryId),
4040
"SelectedCategory.CategoryId"
4141
},
42+
{
43+
(Expression<Func<LowerModel, int>>)(testModel => testModel.selectedcategory.CategoryId),
44+
"selectedcategory.CategoryId"
45+
},
4246
{
4347
(Expression<Func<TestModel, string>>)(model => model.SelectedCategory.CategoryName.MainCategory),
4448
"SelectedCategory.CategoryName.MainCategory"
@@ -71,6 +75,10 @@ public static TheoryData<Expression, string> ExpressionAndTexts
7175
(Expression<Func<IList<TestModel>, Category>>)(model => model[i].SelectedCategory),
7276
"[3].SelectedCategory"
7377
},
78+
{
79+
(Expression<Func<IList<LowerModel>, Category>>)(model => model[i].selectedcategory),
80+
"[3].selectedcategory"
81+
},
7482
{
7583
(Expression<Func<IDictionary<string, TestModel>, string>>)(model => model[key].SelectedCategory.CategoryName.MainCategory),
7684
"[TestModel].SelectedCategory.CategoryName.MainCategory"
@@ -87,10 +95,18 @@ public static TheoryData<Expression, string> ExpressionAndTexts
8795
(Expression<Func<IList<TestModel>, int>>)(model => model[2].PreferredCategories[i].CategoryId),
8896
"[2].PreferredCategories[3].CategoryId"
8997
},
98+
{
99+
(Expression<Func<IList<LowerModel>, int>>)(model => model[2].preferredcategories[i].CategoryId),
100+
"[2].preferredcategories[3].CategoryId"
101+
},
90102
{
91103
(Expression<Func<IList<TestModel>, string>>)(model => model.FirstOrDefault().Name),
92104
"Name"
93105
},
106+
{
107+
(Expression<Func<IList<LowerModel>, string>>)(model => model.FirstOrDefault().name),
108+
"name"
109+
},
94110
{
95111
(Expression<Func<IList<TestModel>, string>>)(model => model.FirstOrDefault().Model),
96112
"Model"
@@ -285,10 +301,22 @@ public static TheoryData<Expression, Expression> NonEquivalentExpressions
285301
(Expression<Func<TestModel, Category>>)(model => model.SelectedCategory),
286302
(Expression<Func<TestModel, CategoryName>>)(model => model.SelectedCategory.CategoryName)
287303
},
304+
{
305+
(Expression<Func<TestModel, CategoryName>>)(model => model.SelectedCategory.CategoryName),
306+
(Expression<Func<LowerModel, CategoryName>>)(model => model.selectedcategory.CategoryName)
307+
},
288308
{
289309
(Expression<Func<TestModel, string>>)(model => model.Model),
290310
(Expression<Func<TestModel, string>>)(model => model.Name)
291311
},
312+
{
313+
(Expression<Func<TestModel, string>>)(model => model.Model),
314+
(Expression<Func<LowerModel, string>>)(model => model.model)
315+
},
316+
{
317+
(Expression<Func<TestModel, string>>)(model => model.Name),
318+
(Expression<Func<LowerModel, string>>)(model => model.name)
319+
},
292320
{
293321
(Expression<Func<TestModel, CategoryName>>)(model => model.SelectedCategory.CategoryName),
294322
(Expression<Func<TestModel, string>>)(model => value)
@@ -301,6 +329,10 @@ public static TheoryData<Expression, Expression> NonEquivalentExpressions
301329
(Expression<Func<IList<TestModel>, Category>>)(model => model[2].SelectedCategory),
302330
(Expression<Func<TestModel, string>>)(model => model.SelectedCategory.CategoryName.MainCategory)
303331
},
332+
{
333+
(Expression<Func<IList<TestModel>, Category>>)(model => model[2].SelectedCategory),
334+
(Expression<Func<IList<LowerModel>, Category>>)(model => model[2].selectedcategory)
335+
},
304336
{
305337
(Expression<Func<TestModel, int>>)(testModel => testModel.SelectedCategory.CategoryId),
306338
(Expression<Func<TestModel, Category>>)(model => model.SelectedCategory)
@@ -309,6 +341,10 @@ public static TheoryData<Expression, Expression> NonEquivalentExpressions
309341
(Expression<Func<IDictionary<string, TestModel>, string>>)(model => model[key].SelectedCategory.CategoryName.MainCategory),
310342
(Expression<Func<TestModel, Category>>)(model => model.SelectedCategory)
311343
},
344+
{
345+
(Expression<Func<IDictionary<string, TestModel>, string>>)(model => model[key].SelectedCategory.CategoryName.MainCategory),
346+
(Expression<Func<IDictionary<string, LowerModel>, string>>)(model => model[key].selectedcategory.CategoryName.MainCategory)
347+
},
312348
{
313349
(Expression<Func<TestModel, string>>)(m => Model),
314350
(Expression<Func<TestModel, string>>)(m => m.Model)
@@ -408,6 +444,17 @@ private class TestModel
408444
public IList<Category> PreferredCategories { get; set; }
409445
}
410446

447+
private class LowerModel
448+
{
449+
public string name { get; set; }
450+
451+
public string model { get; set; }
452+
453+
public Category selectedcategory { get; set; }
454+
455+
public IList<Category> preferredcategories { get; set; }
456+
}
457+
411458
private class Category
412459
{
413460
public int CategoryId { get; set; }

0 commit comments

Comments
 (0)