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

Commit 25fbe6f

Browse files
author
Justin Kotalik
committed
Fixes HashCode issue
1 parent b4d8918 commit 25fbe6f

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/Microsoft.AspNetCore.Http.Abstractions/PathString.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ public bool Equals(PathString other)
224224
/// <returns>True if both PathString values are equal</returns>
225225
public bool Equals(PathString other, StringComparison comparisonType)
226226
{
227-
if (!this.HasValue && !other.HasValue)
227+
if (!HasValue && !other.HasValue)
228228
{
229229
return true;
230230
}
@@ -251,7 +251,7 @@ public override bool Equals(object obj)
251251
/// <returns>The hash code</returns>
252252
public override int GetHashCode()
253253
{
254-
return (_value != null ? StringComparer.OrdinalIgnoreCase.GetHashCode(_value) : 0);
254+
return (HasValue ? StringComparer.OrdinalIgnoreCase.GetHashCode(_value) : 0);
255255
}
256256

257257
/// <summary>

test/Microsoft.AspNetCore.Http.Abstractions.Tests/PathStringTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ public void NotEquals_EmptyPathStringAndNonNullPathString()
4848
Assert.NotEqual(pathString, PathString.Empty);
4949
}
5050

51+
[Fact]
52+
public void HashCode_CheckNullAndEmptyHaveSameHashcodes()
53+
{
54+
Assert.Equal(PathString.Empty.GetHashCode(), default(PathString).GetHashCode());
55+
}
56+
5157
[Theory]
5258
[InlineData(null, null)]
5359
[InlineData("", null)]

0 commit comments

Comments
 (0)