Correctly normalize file path from network shares (dotnet/aspnetcore-tooling#298)
* Correctly normalize file path from network shares
* Feedback
\n\nCommit migrated from 8ee676d84c
This commit is contained in:
parent
8775af3309
commit
1657080589
|
|
@ -52,7 +52,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
var file = new FileInfo(absolutePath);
|
var file = new FileInfo(absolutePath);
|
||||||
if (!absolutePath.StartsWith(absoluteBasePath))
|
if (!absolutePath.StartsWith(absoluteBasePath))
|
||||||
{
|
{
|
||||||
throw new InvalidOperationException($"The file '{file.FullName}' is not a descendent of the base path '{absoluteBasePath}'.");
|
throw new InvalidOperationException($"The file '{absolutePath}' is not a descendent of the base path '{absoluteBasePath}'.");
|
||||||
}
|
}
|
||||||
|
|
||||||
var relativePhysicalPath = file.FullName.Substring(absoluteBasePath.Length + 1); // Include leading separator
|
var relativePhysicalPath = file.FullName.Substring(absoluteBasePath.Length + 1); // Include leading separator
|
||||||
|
|
@ -68,9 +68,15 @@ namespace Microsoft.AspNetCore.Razor.Language
|
||||||
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(path));
|
throw new ArgumentException(Resources.ArgumentCannotBeNullOrEmpty, nameof(path));
|
||||||
}
|
}
|
||||||
|
|
||||||
var absolutePath = path;
|
var absolutePath = path.Replace('\\', '/');
|
||||||
if (!absolutePath.StartsWith(Root, StringComparison.OrdinalIgnoreCase))
|
|
||||||
|
// Check if the given path is an absolute path. It is absolute if,
|
||||||
|
// 1. It starts with Root or
|
||||||
|
// 2. It is a network share path and starts with a '//'. Eg. //servername/some/network/folder
|
||||||
|
if (!absolutePath.StartsWith(Root, StringComparison.OrdinalIgnoreCase) &&
|
||||||
|
!absolutePath.StartsWith("//", StringComparison.OrdinalIgnoreCase))
|
||||||
{
|
{
|
||||||
|
// This is not an absolute path. Strip the leading slash if any and combine it with Root.
|
||||||
if (path[0] == '/' || path[0] == '\\')
|
if (path[0] == '/' || path[0] == '\\')
|
||||||
{
|
{
|
||||||
path = path.Substring(1);
|
path = path.Substring(1);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue