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

Commit 65e57d2

Browse files
committed
Add PathString+string operator to prevent too much string<->PathString implicit conversion.
1 parent 86bd393 commit 65e57d2

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/Microsoft.AspNet.Http.Core/PathString.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,18 @@ public override int GetHashCode()
227227
return string.Concat(left, right.ToString());
228228
}
229229

230+
/// <summary>
231+
/// </summary>
232+
/// <param name="left">The left parameter</param>
233+
/// <param name="right">The right parameter</param>
234+
/// <returns>The ToString combination of both values</returns>
235+
public static string operator +(PathString left, string right)
236+
{
237+
// This overload exists to prevent the implicit string<->PathString converter from
238+
// trying to call the PathString+PathString operator for things that are not path strings.
239+
return string.Concat(left.ToString(), right);
240+
}
241+
230242
/// <summary>
231243
/// Operator call through to Add
232244
/// </summary>

test/Microsoft.AspNet.Http.Core.Tests/PathStringTests.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ public void ImplicitStringConverters_WorksWithAdd()
6363

6464
var result = scheme + "://" + host + pathBase + path + query + fragment;
6565
Assert.Equal("http://localhost:80/base/path?query#frag", result);
66+
67+
result = pathBase + path + query + fragment;
68+
Assert.Equal("/base/path?query#frag", result);
69+
70+
result = path + "text";
71+
Assert.Equal("/pathtext", result);
6672
}
6773
}
6874
}

0 commit comments

Comments
 (0)