This repository has been archived by the owner on Dec 14, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Normalize paths in RazorViewEngine prior to invoking page factory
Fixes #6672
- Loading branch information
Showing
16 changed files
with
190 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
test/Microsoft.AspNetCore.Mvc.Core.Test/Internal/ViewEnginePathTest.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright (c) .NET Foundation. All rights reserved. | ||
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. | ||
|
||
using Xunit; | ||
|
||
namespace Microsoft.AspNetCore.Mvc.Internal | ||
{ | ||
public class ViewEnginePathTest | ||
{ | ||
[Theory] | ||
[InlineData("Views/../Home/Index.cshtml", "/Home/Index.cshtml")] | ||
[InlineData("/Views/Home/../Shared/Partial.cshtml", "/Views/Shared/Partial.cshtml")] | ||
[InlineData("/Views/Shared/./Partial.cshtml", "/Views/Shared/Partial.cshtml")] | ||
[InlineData("//Views/Index.cshtml", "/Views/Index.cshtml")] | ||
public void ResolvePath_ResolvesPathTraversals(string input, string expected) | ||
{ | ||
// Arrange & Act | ||
var result = ViewEnginePath.ResolvePath(input); | ||
|
||
// Assert | ||
Assert.Equal(expected, result); | ||
} | ||
|
||
[Theory] | ||
[InlineData("../Index.cshtml")] | ||
[InlineData("Views/../../Index.cshtml")] | ||
[InlineData("Views/../Shared/../../Index.cshtml")] | ||
public void ResolvePath_DoesNotTraversePastApplicationRoot(string input) | ||
{ | ||
// Arrange | ||
var result = ViewEnginePath.ResolvePath(input); | ||
|
||
// Assert | ||
Assert.Same(input, result); | ||
} | ||
|
||
[Theory] | ||
[InlineData("/Views/Index.cshtml")] | ||
[InlineData(@"/Views\Index.cshtml")] | ||
[InlineData("Index..cshtml")] | ||
[InlineData("/directory.with.periods/sub-dir/index.cshtml")] | ||
[InlineData("file.with.periods.cshtml")] | ||
public void ResolvePath_DoesNotModifyPathsWithoutTraversals(string input) | ||
{ | ||
// Arrange & Act | ||
var result = ViewEnginePath.ResolvePath(input); | ||
|
||
// Assert | ||
Assert.Same(input, result); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions
1
test/WebSites/RazorWebSite/EmbeddedResources/Views/EmbeddedViews/EmbeddedPartial.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Hello from EmbeddedHome\EmbeddedPartial |
File renamed without changes.
2 changes: 2 additions & 0 deletions
2
test/WebSites/RazorWebSite/EmbeddedResources/Views/EmbeddedViews/RelativeNonPath.cshtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
@{ Layout = "../EmbeddedShared/_Layout"; } | ||
@Html.Partial("./EmbeddedPartial") |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters