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

Commit

Permalink
Use ViewEnginePath to handle current path
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanbrandenburg committed Apr 24, 2017
1 parent 783bdf7 commit 975517b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
9 changes: 8 additions & 1 deletion src/Microsoft.AspNetCore.Mvc.Core/Internal/ViewEnginePath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Microsoft.AspNetCore.Mvc.Core.Internal
{
public static class ViewEnginePath
{
private const string CurrentDirectoryToken = ".";
private const string ParentDirectoryToken = "..";
private static readonly char[] _pathSeparators = new[] { '/', '\\' };

Expand Down Expand Up @@ -70,6 +71,11 @@ public static string ResolvePath(string path)
}
pathSegments.RemoveAt(pathSegments.Count - 1);
}
else if (segment.Equals(CurrentDirectoryToken, StringComparison.Ordinal))
{
// We already have the current directory
continue;
}
else
{
pathSegments.Add(segment);
Expand All @@ -89,7 +95,8 @@ public static string ResolvePath(string path)

private static bool RequiresPathResolution(string path)
{
return path.IndexOf(ParentDirectoryToken, StringComparison.Ordinal) != -1;
return path.IndexOf(ParentDirectoryToken, StringComparison.Ordinal) != -1 ||
path.IndexOf(CurrentDirectoryToken, StringComparison.Ordinal) != -1;
}
}
}
5 changes: 0 additions & 5 deletions src/Microsoft.AspNetCore.Mvc.Core/UrlHelperExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -457,11 +457,6 @@ private static object CalculatePageName(ActionContext actionContext, string page
throw new InvalidOperationException(Resources.FormatUrlHelper_RelativePagePathIsNotSupported(pageName));
}

if(pageName.StartsWith("./"))
{
pageName = pageName.Substring(2, pageName.Length - 2);
}

return ViewEnginePath.CombinePath(currentPagePath, pageName);
}

Expand Down
12 changes: 6 additions & 6 deletions test/Microsoft.AspNetCore.Mvc.FunctionalTests/RazorPagesTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -921,8 +921,8 @@ public async Task RedirectToSibling_RedirectsToParentDirectory()
public async Task TagHelpers_SupportSiblingRoutes()
{
// Arrange
var expected =
@"<form method=""post"" action=""/Pages/TagHelper/CrossPost""></form>
var expected =
@"<form method=""post"" action=""/Pages/TagHelper/CrossPost""></form>
<a href=""/Pages/TagHelper/SelfPost/12"" />
<input type=""image"" formaction=""/Pages/TagHelper/CrossPost#my-fragment"" />";

Expand All @@ -937,8 +937,8 @@ public async Task TagHelpers_SupportSiblingRoutes()
public async Task TagHelpers_SupportSubDirectoryRoutes()
{
// Arrange
var expected =
@"<form method=""post"" action=""/Pages/TagHelper/SubDir/SubDirPage""></form>
var expected =
@"<form method=""post"" action=""/Pages/TagHelper/SubDir/SubDirPage""></form>
<a href=""/Pages/TagHelper/SubDir/SubDirPage/12"" />
<input type=""image"" formaction=""/Pages/TagHelper/SubDir/SubDirPage#my-fragment"" />";

Expand All @@ -953,8 +953,8 @@ public async Task TagHelpers_SupportSubDirectoryRoutes()
public async Task TagHelpers_SupportsPathNavigation()
{
// Arrange
var expected =
@"<form method=""post"" action=""/HelloWorld""></form>
var expected =
@"<form method=""post"" action=""/HelloWorld""></form>
<a href=""/Pages/Redirects/RedirectToIndex"" />
<input type=""image"" formaction=""/Pages/Admin#my-fragment"" />";

Expand Down

0 comments on commit 975517b

Please sign in to comment.