Skip to content
This repository was archived by the owner on Dec 14, 2018. It is now read-only.

Commit 956441a

Browse files
sqdavidpranavkm
authored andcommitted
Ignore created URI if Assembly.CodeBase contains a fragment (#8556)
* Fixes #8367
1 parent 67a1f2d commit 956441a

File tree

2 files changed

+51
-2
lines changed

2 files changed

+51
-2
lines changed

src/Microsoft.AspNetCore.Mvc.Core/ApplicationParts/RelatedAssemblyAttribute.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@ internal static IReadOnlyList<Assembly> GetRelatedAssemblies(
115115

116116
internal static string GetAssemblyLocation(Assembly assembly)
117117
{
118-
if (Uri.TryCreate(assembly.CodeBase, UriKind.Absolute, out var result) && result.IsFile)
118+
if (Uri.TryCreate(assembly.CodeBase, UriKind.Absolute, out var result) &&
119+
result.IsFile && string.IsNullOrWhiteSpace(result.Fragment))
119120
{
120121
return result.LocalPath;
121122
}

test/Microsoft.AspNetCore.Mvc.Core.Test/ApplicationParts/RelatedAssemblyPartTest.cs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public void GetAssemblyLocation_UsesCodeBase()
8080
{
8181
// Arrange
8282
var destination = Path.Combine(AssemblyDirectory, "RelatedAssembly.dll");
83-
var codeBase = "file://x/file/Assembly.dll";
83+
var codeBase = "file://x:/file/Assembly.dll";
8484
var expected = new Uri(codeBase).LocalPath;
8585
var assembly = new TestAssembly
8686
{
@@ -109,6 +109,54 @@ public void GetAssemblyLocation_UsesLocation_IfCodeBaseIsNotLocal()
109109
Assert.Equal(expected, actual);
110110
}
111111

112+
[Fact]
113+
public void GetAssemblyLocation_CodeBase_HasPoundCharacterUnixPath()
114+
{
115+
var destination = Path.Combine(AssemblyDirectory, "RelatedAssembly.dll");
116+
var expected = @"/etc/#NIN/dotnetcore/tryx/try1.dll";
117+
var assembly = new TestAssembly
118+
{
119+
CodeBaseSettable = "file:///etc/#NIN/dotnetcore/tryx/try1.dll",
120+
LocationSettable = expected,
121+
};
122+
123+
// Act
124+
var actual = RelatedAssemblyAttribute.GetAssemblyLocation(assembly);
125+
Assert.Equal(expected, actual);
126+
}
127+
128+
[Fact]
129+
public void GetAssemblyLocation_CodeBase_HasPoundCharacterUNCPath()
130+
{
131+
var destination = Path.Combine(AssemblyDirectory, "RelatedAssembly.dll");
132+
var expected = @"\\server\#NIN\dotnetcore\tryx\try1.dll";
133+
var assembly = new TestAssembly
134+
{
135+
CodeBaseSettable = "file://server/#NIN/dotnetcore/tryx/try1.dll",
136+
LocationSettable = expected,
137+
};
138+
139+
// Act
140+
var actual = RelatedAssemblyAttribute.GetAssemblyLocation(assembly);
141+
Assert.Equal(expected, actual);
142+
}
143+
144+
[Fact]
145+
public void GetAssemblyLocation_CodeBase_HasPoundCharacterDOSPath()
146+
{
147+
var destination = Path.Combine(AssemblyDirectory, "RelatedAssembly.dll");
148+
var expected = @"C:\#NIN\dotnetcore\tryx\try1.dll";
149+
var assembly = new TestAssembly
150+
{
151+
CodeBaseSettable = "file:///C:/#NIN/dotnetcore/tryx/try1.dll",
152+
LocationSettable = expected,
153+
};
154+
155+
// Act
156+
var actual = RelatedAssemblyAttribute.GetAssemblyLocation(assembly);
157+
Assert.Equal(expected, actual);
158+
}
159+
112160
private class TestAssembly : Assembly
113161
{
114162
public override AssemblyName GetName()

0 commit comments

Comments
 (0)