Improved SinglePage algorithm. Bumped package version to 1.6.6

This commit is contained in:
2023-06-29 09:29:21 -07:00
parent dc1abd516b
commit 36872164c5
3 changed files with 109 additions and 64 deletions

View File

@@ -672,14 +672,7 @@ namespace MontoyaTech.Rest.Net
//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);
//Process the components and handle any directory navigations.
for (int i = 0; i < components.Count; i++)
{
if (components[i].Trim() == "..")
@@ -711,17 +704,50 @@ namespace MontoyaTech.Rest.Net
}
}
if (components.Count == 0)
return false;
//Check the components and remove any that are invalid.
while (components.Count > 0)
{
string path = Path.Combine(basePath, components[0]);
if (File.Exists(path) || Directory.Exists(path))
{
break;
}
//If we have no more components and we are missing an extension and with .html a file exists, then use it.
else if (components.Count == 1 && !components[0].Contains('.') && File.Exists(path + ".html"))
{
components[0] = components[0] + ".html";
break;
}
else
{
components.RemoveAt(0);
}
}
//Quirk, if the components is now empty, point to the indexFile
if (components.Count == 0)
components.Add(indexFile);
//Combine the path into an absolute path
var absolutePath = Path.Combine(basePath, components.Separate(Path.DirectorySeparatorChar));
//If a file exists, return true
if (File.Exists(absolutePath))
{
resolvedPath = absolutePath;
return true;
}
//If a file exists with adding .html then use that
else if (File.Exists(absolutePath + ".html"))
{
resolvedPath = absolutePath + ".html";
return true;
}
//If a directory exists then use that
else if (Directory.Exists(absolutePath))
{
resolvedPath = absolutePath;
@@ -730,40 +756,12 @@ namespace MontoyaTech.Rest.Net
return true;
}
//Otherwise redirect to index.html
else
{
//Try to components that don't exist and try again
while (components.Count > 0)
{
string path = Path.Combine(basePath, components[0]);
resolvedPath = Path.Combine(basePath, indexFile);
if (File.Exists(path) || Directory.Exists(path))
break;
else
components.RemoveAt(0);
}
if (components.Count == 0)
return false;
absolutePath = Path.Combine(basePath, components.Separate(Path.PathSeparator));
if (File.Exists(absolutePath))
{
resolvedPath = absolutePath;
return true;
}
else if (Directory.Exists(absolutePath))
{
resolvedPath = absolutePath;
isDirectory = true;
return true;
}
return false;
return true;
}
}
}

View File

@@ -17,7 +17,7 @@
<AssemblyName>MontoyaTech.Rest.Net</AssemblyName>
<RootNamespace>MontoyaTech.Rest.Net</RootNamespace>
<GenerateDocumentationFile>True</GenerateDocumentationFile>
<Version>1.6.5</Version>
<Version>1.6.6</Version>
<PackageReleaseNotes></PackageReleaseNotes>
<PackageIcon>Logo_Symbol_Black_Outline.png</PackageIcon>
</PropertyGroup>