Do case insensitive comparison in DefaultRazorProjectFileSystem.GetItem (dotnet/aspnetcore-tooling#709)
\n\nCommit migrated from ff305c700f
This commit is contained in:
parent
4e16cfd4da
commit
0659180119
|
|
@ -50,7 +50,7 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
var absolutePath = NormalizeAndEnsureValidPath(path);
|
||||
|
||||
var file = new FileInfo(absolutePath);
|
||||
if (!absolutePath.StartsWith(absoluteBasePath))
|
||||
if (!absolutePath.StartsWith(absoluteBasePath, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
throw new InvalidOperationException($"The file '{absolutePath}' is not a descendent of the base path '{absoluteBasePath}'.");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ using System;
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using Microsoft.AspNetCore.Testing;
|
||||
using Microsoft.AspNetCore.Testing.xunit;
|
||||
using Xunit;
|
||||
|
||||
namespace Microsoft.AspNetCore.Razor.Language
|
||||
|
|
@ -258,6 +259,26 @@ namespace Microsoft.AspNetCore.Razor.Language
|
|||
Assert.Equal(Path.Combine("Views", "About", "About.cshtml"), item.RelativePhysicalPath);
|
||||
}
|
||||
|
||||
[ConditionalFact]
|
||||
[OSSkipCondition(OperatingSystems.Linux, SkipReason = "This test does not makes sense for case sensitive Operating Systems.")]
|
||||
public void GetItem_MismatchedCase_ReturnsFileFromDisk()
|
||||
{
|
||||
// Arrange
|
||||
var filePath = "/Views/About/About.cshtml";
|
||||
var lowerCaseTestFolder = TestFolder.ToLower();
|
||||
var fileSystem = new DefaultRazorProjectFileSystem(lowerCaseTestFolder);
|
||||
|
||||
// Act
|
||||
var item = fileSystem.GetItem(filePath, fileKind: null);
|
||||
|
||||
// Assert
|
||||
Assert.True(item.Exists);
|
||||
Assert.Equal(filePath, item.FilePath);
|
||||
Assert.Equal("/", item.BasePath);
|
||||
Assert.Equal(Path.Combine(lowerCaseTestFolder, "Views", "About", "About.cshtml"), item.PhysicalPath);
|
||||
Assert.Equal(Path.Combine("Views", "About", "About.cshtml"), item.RelativePhysicalPath);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void GetItem_ReturnsNotFoundResult()
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in New Issue