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

Local relative paths allow "./" prefix #6202

Merged
merged 1 commit into from
Apr 25, 2017

Conversation

ryanbrandenburg
Copy link
Contributor

Fixes #6190 by allowing ./ relative paths.

@@ -457,6 +457,11 @@ private static object CalculatePageName(ActionContext actionContext, string page
throw new InvalidOperationException(Resources.FormatUrlHelper_RelativePagePathIsNotSupported(pageName));
}

if(pageName.StartsWith("./"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spacing

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StringComparison.Ordinal

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do back-slashes too? ViewEnginePath allows ..\ for path navigation.

@@ -404,6 +404,6 @@
<value>No page named '{0}' matches the supplied values.</value>
</data>
<data name="UrlHelper_RelativePagePathIsNotSupported" xml:space="preserve">
<value>The relative page path '{0}' can only can only be used while executing a Razor Page. Specify a root relative path with a leading '/' to generate a URL outside of a Razor Page.</value>
<value>The relative page path '{0}' can only be used while executing a Razor Page. Specify a root relative path with a leading '/' to generate a URL outside of a Razor Page.</value>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops

@@ -457,6 +457,11 @@ private static object CalculatePageName(ActionContext actionContext, string page
throw new InvalidOperationException(Resources.FormatUrlHelper_RelativePagePathIsNotSupported(pageName));
}

if(pageName.StartsWith("./"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StringComparison.Ordinal

@@ -457,6 +457,11 @@ 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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pageName = pageName.Substring(2);

@@ -457,6 +457,11 @@ private static object CalculatePageName(ActionContext actionContext, string page
throw new InvalidOperationException(Resources.FormatUrlHelper_RelativePagePathIsNotSupported(pageName));
}

if(pageName.StartsWith("./"))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we do back-slashes too? ViewEnginePath allows ..\ for path navigation.

@ryanbrandenburg ryanbrandenburg force-pushed the rybrande/LocalRelativePaths branch from 975517b to 2f693bd Compare April 24, 2017 23:38
@@ -8,4 +8,6 @@
public IActionResult OnGetRedirectToSubDir() => RedirectToPage("SubDir/SubDirPage");

public IActionResult OnGetRedirectToParent() => RedirectToPage("../Conventions/AuthFolder/Index");

public IActionResult OnGetRedirectToDotSlash() => RedirectToPage("./SubDir/SubDirPage");
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Double check my thinking that /Pages/Redirects/SubDir/SubDirPage is the correct outcome of this (as tested above). This seems correct to me but some instinct keeps wanting the correct outcome to be /Pages/Redirects/RedirectToSibling/SubDir/SubDirPage.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. The last segment always gets trimmed.

@ryanbrandenburg
Copy link
Contributor Author

🆙📅

@@ -70,6 +71,11 @@ public static string ResolvePath(string path)
}
pathSegments.RemoveAt(pathSegments.Count - 1);
}
else if (segment.Equals(CurrentDirectoryToken, StringComparison.Ordinal))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ViewEngine test?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added here.

var expected =
@"<form method=""post"" action=""/Pages/TagHelper/SubDir/SubDirPage""></form>
var expected =
@"<form method=""post"" action=""/Pages/TagHelper/SubDir/SubDirPage""></form>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you leave this untabbed?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed in person, leaving this because it's a VS formatting thing.

@ryanbrandenburg ryanbrandenburg force-pushed the rybrande/LocalRelativePaths branch from 8d73d6b to 6d9ad07 Compare April 25, 2017 17:15
@ryanbrandenburg
Copy link
Contributor Author

🆙📅

@ryanbrandenburg ryanbrandenburg force-pushed the rybrande/LocalRelativePaths branch from 6d9ad07 to 7bd801a Compare April 25, 2017 18:46
@ryanbrandenburg ryanbrandenburg force-pushed the rybrande/LocalRelativePaths branch from 7bd801a to 42b988a Compare April 25, 2017 18:58
@ryanbrandenburg ryanbrandenburg merged commit 42b988a into dev Apr 25, 2017
@smitpatel smitpatel deleted the rybrande/LocalRelativePaths branch June 28, 2017 21:00
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants