Ignore created URI if Assembly.CodeBase contains a fragment (#8556)

* Fixes #8367
This commit is contained in:
David J. Quiroga 2018-10-08 14:41:04 -03:00 committed by Pranav K
parent 67a1f2dda9
commit 956441aa68
2 changed files with 51 additions and 2 deletions

View File

@ -115,7 +115,8 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationParts
internal static string GetAssemblyLocation(Assembly assembly)
{
if (Uri.TryCreate(assembly.CodeBase, UriKind.Absolute, out var result) && result.IsFile)
if (Uri.TryCreate(assembly.CodeBase, UriKind.Absolute, out var result) &&
result.IsFile && string.IsNullOrWhiteSpace(result.Fragment))
{
return result.LocalPath;
}

View File

@ -80,7 +80,7 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationParts
{
// Arrange
var destination = Path.Combine(AssemblyDirectory, "RelatedAssembly.dll");
var codeBase = "file://x/file/Assembly.dll";
var codeBase = "file://x:/file/Assembly.dll";
var expected = new Uri(codeBase).LocalPath;
var assembly = new TestAssembly
{
@ -109,6 +109,54 @@ namespace Microsoft.AspNetCore.Mvc.ApplicationParts
Assert.Equal(expected, actual);
}
[Fact]
public void GetAssemblyLocation_CodeBase_HasPoundCharacterUnixPath()
{
var destination = Path.Combine(AssemblyDirectory, "RelatedAssembly.dll");
var expected = @"/etc/#NIN/dotnetcore/tryx/try1.dll";
var assembly = new TestAssembly
{
CodeBaseSettable = "file:///etc/#NIN/dotnetcore/tryx/try1.dll",
LocationSettable = expected,
};
// Act
var actual = RelatedAssemblyAttribute.GetAssemblyLocation(assembly);
Assert.Equal(expected, actual);
}
[Fact]
public void GetAssemblyLocation_CodeBase_HasPoundCharacterUNCPath()
{
var destination = Path.Combine(AssemblyDirectory, "RelatedAssembly.dll");
var expected = @"\\server\#NIN\dotnetcore\tryx\try1.dll";
var assembly = new TestAssembly
{
CodeBaseSettable = "file://server/#NIN/dotnetcore/tryx/try1.dll",
LocationSettable = expected,
};
// Act
var actual = RelatedAssemblyAttribute.GetAssemblyLocation(assembly);
Assert.Equal(expected, actual);
}
[Fact]
public void GetAssemblyLocation_CodeBase_HasPoundCharacterDOSPath()
{
var destination = Path.Combine(AssemblyDirectory, "RelatedAssembly.dll");
var expected = @"C:\#NIN\dotnetcore\tryx\try1.dll";
var assembly = new TestAssembly
{
CodeBaseSettable = "file:///C:/#NIN/dotnetcore/tryx/try1.dll",
LocationSettable = expected,
};
// Act
var actual = RelatedAssemblyAttribute.GetAssemblyLocation(assembly);
Assert.Equal(expected, actual);
}
private class TestAssembly : Assembly
{
public override AssemblyName GetName()