Added support for cases where the parent directory is included in the request path. Added unit tests to check this case. Bumped package version to 1.6.4
This commit is contained in:
parent
46aab308fa
commit
4617f861fc
@ -46,6 +46,16 @@ namespace Rest.Net.Tests
|
||||
resolvedPath.Should().BeEquivalentTo(this.TestFile);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ServeMultiple_File_WithParentDirectory_ShouldWork()
|
||||
{
|
||||
HttpListenerResponseExtensions.ResolveMultiPagePath(this.BaseDirectory, "test/test.html", null, out string resolvedPath, out bool isDirectory).Should().BeTrue();
|
||||
|
||||
isDirectory.Should().BeFalse();
|
||||
|
||||
resolvedPath.Should().BeEquivalentTo(this.TestFile);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ServeMultiple_Directory_ShouldWork()
|
||||
{
|
||||
@ -88,6 +98,16 @@ namespace Rest.Net.Tests
|
||||
resolvedPath.Should().BeEquivalentTo(this.TestFile);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ServeSingle_File_WithParentDirectory_ShouldWork()
|
||||
{
|
||||
HttpListenerResponseExtensions.ResolveSinglePagePath(this.BaseDirectory, "test/test.html", null, out string resolvedPath, out bool isDirectory).Should().BeTrue();
|
||||
|
||||
isDirectory.Should().BeFalse();
|
||||
|
||||
resolvedPath.Should().BeEquivalentTo(this.TestFile);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ServeSingle_Directory_ShouldWork()
|
||||
{
|
||||
|
@ -547,9 +547,20 @@ namespace MontoyaTech.Rest.Net
|
||||
if (string.IsNullOrWhiteSpace(requestPath) || requestPath == "/" || requestPath == ".")
|
||||
requestPath = indexFile;
|
||||
|
||||
//See if there is a parent directory in the basePath, if so get it
|
||||
var parentDirectory = basePath.Split(new char[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries).LastOrDefault();
|
||||
|
||||
//Break the request path into it's components so we can enfore staying in the base path.
|
||||
var components = requestPath.Split(new char[] { '/', '\\' }, StringSplitOptions.RemoveEmptyEntries).ToList();
|
||||
|
||||
//If the first component is the parent directory, then remove it
|
||||
if (components.Count > 0 && components[0].Equals(parentDirectory, StringComparison.CurrentCultureIgnoreCase))
|
||||
components.RemoveAt(0);
|
||||
|
||||
//Quirk, if the components is now empty, point to the indexFile
|
||||
if (components.Count == 0)
|
||||
components.Add(indexFile);
|
||||
|
||||
for (int i = 0; i < components.Count; i++)
|
||||
{
|
||||
if (components[i].Trim() == "..")
|
||||
|
@ -17,7 +17,7 @@
|
||||
<AssemblyName>MontoyaTech.Rest.Net</AssemblyName>
|
||||
<RootNamespace>MontoyaTech.Rest.Net</RootNamespace>
|
||||
<GenerateDocumentationFile>True</GenerateDocumentationFile>
|
||||
<Version>1.6.3</Version>
|
||||
<Version>1.6.4</Version>
|
||||
<PackageReleaseNotes></PackageReleaseNotes>
|
||||
<PackageIcon>Logo_Symbol_Black_Outline.png</PackageIcon>
|
||||
</PropertyGroup>
|
||||
|
Loading…
x
Reference in New Issue
Block a user