1
0
Fork 0

Escape paths sent to the browser to avoid awkward pathing issues.

This commit is contained in:
Starbeamrainbowlabs 2016-08-10 17:46:43 +01:00
parent d777ada143
commit b443508c42
2 changed files with 5 additions and 4 deletions

View File

@ -24,7 +24,7 @@ namespace GalleryShare
Dictionary<string, string> pathReplacements = new Dictionary<string, string>()
{
{ "%20", " " }
["%20"] = " "
};
public int Port { get { return port; } }
@ -118,6 +118,7 @@ namespace GalleryShare
string result = Path.GetFullPath(Path.Combine(servingDirectory, "." + rawUrl));
if(result.IndexOf("?") != -1)
result = result.Substring(0, result.IndexOf("?"));
result = Uri.UnescapeDataString(result);
foreach (KeyValuePair<string, string> replacePair in pathReplacements)
result = result.Replace(replacePair.Key, replacePair.Value);
return result;

View File

@ -46,7 +46,7 @@ namespace GalleryShare.RequestRouter
await xmlData.WriteStartDocumentAsync();
await xmlData.WriteProcessingInstructionAsync("xml-stylesheet", "type=\"text/xsl\" href=\"/!Transform-DirListing.xslt\"");
await xmlData.WriteStartElementAsync(null, "DirectoryListing", null);
await xmlData.WriteElementStringAsync(null, "CurrentDirectory", null, cycle.Request.RawUrl);
await xmlData.WriteElementStringAsync(null, "CurrentDirectory", null, Uri.EscapeDataString(cycle.Request.RawUrl));
await xmlData.WriteStartElementAsync(null, "Contents", null);
foreach (string directoryName in dirDirectories)
@ -54,7 +54,7 @@ namespace GalleryShare.RequestRouter
await xmlData.WriteStartElementAsync(null, "ListingEntry", null);
await xmlData.WriteAttributeStringAsync(null, "Type", null, "Directory");
await xmlData.WriteElementStringAsync(null, "Name", null, "/" + directoryName.Substring(parentServer.ServingDirectory.Length));
await xmlData.WriteElementStringAsync(null, "Name", null, Uri.EscapeDataString("/" + directoryName.Substring(parentServer.ServingDirectory.Length)));
await xmlData.WriteElementStringAsync(null, "ItemCount", null, Directory.GetFileSystemEntries(directoryName).Length.ToString());
await xmlData.WriteEndElementAsync();
@ -64,7 +64,7 @@ namespace GalleryShare.RequestRouter
await xmlData.WriteStartElementAsync(null, "ListingEntry", null);
await xmlData.WriteAttributeStringAsync(null, "Type", null, "File");
await xmlData.WriteElementStringAsync(null, "Name", null, "/" + filename.Substring(parentServer.ServingDirectory.Length));
await xmlData.WriteElementStringAsync(null, "Name", null, Uri.EscapeDataString("/" + filename.Substring(parentServer.ServingDirectory.Length)));
await xmlData.WriteEndElementAsync();
}