-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Local relative paths allow "./" prefix #6202
Conversation
@@ -457,6 +457,11 @@ private static object CalculatePageName(ActionContext actionContext, string page | |||
throw new InvalidOperationException(Resources.FormatUrlHelper_RelativePagePathIsNotSupported(pageName)); | |||
} | |||
|
|||
if(pageName.StartsWith("./")) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
spacing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
StringComparison.Ordinal
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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("./")) |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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("./")) |
There was a problem hiding this comment.
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.
975517b
to
2f693bd
Compare
@@ -8,4 +8,6 @@ | |||
public IActionResult OnGetRedirectToSubDir() => RedirectToPage("SubDir/SubDirPage"); | |||
|
|||
public IActionResult OnGetRedirectToParent() => RedirectToPage("../Conventions/AuthFolder/Index"); | |||
|
|||
public IActionResult OnGetRedirectToDotSlash() => RedirectToPage("./SubDir/SubDirPage"); |
There was a problem hiding this comment.
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
.
There was a problem hiding this comment.
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.
🆙📅 |
@@ -70,6 +71,11 @@ public static string ResolvePath(string path) | |||
} | |||
pathSegments.RemoveAt(pathSegments.Count - 1); | |||
} | |||
else if (segment.Equals(CurrentDirectoryToken, StringComparison.Ordinal)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you add a test in https://github.com/aspnet/Mvc/blob/dev/test/Microsoft.AspNetCore.Mvc.Razor.Test/RazorViewEngineTest.cs#L1475 if we're changing ViewEnginePath
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ViewEngine test?
There was a problem hiding this comment.
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> |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
8d73d6b
to
6d9ad07
Compare
🆙📅 |
6d9ad07
to
7bd801a
Compare
7bd801a
to
42b988a
Compare
Fixes #6190 by allowing
./
relative paths.