Fixes issue that url encodes colons when specifying a web server that doesn't run on port 80 for FTP uploads. Bug #282

This commit is contained in:
Gregory 2014-09-23 20:17:42 -04:00
parent e3bdefe37c
commit ee60e9cbc6

View file

@ -153,8 +153,6 @@ public string GetHttpHomePath()
HttpHomePathAutoAddSubFolderPath = false; HttpHomePathAutoAddSubFolderPath = false;
} }
HttpHomePath = URLHelpers.RemovePrefixes(HttpHomePath);
return NameParser.Parse(NameParserType.URL, HttpHomePath.Replace("%host", Host)); return NameParser.Parse(NameParserType.URL, HttpHomePath.Replace("%host", Host));
} }
@ -179,51 +177,54 @@ public string GetUriPath(string filename, string subFolderPath = null)
subFolderPath = URLHelpers.URLPathEncode(subFolderPath); subFolderPath = URLHelpers.URLPathEncode(subFolderPath);
string httpHomePath = GetHttpHomePath(); UriBuilder httpHomeUri;
httpHomePath = URLHelpers.URLPathEncode(httpHomePath); var httpHomePath = GetHttpHomePath();
string path;
if (string.IsNullOrEmpty(httpHomePath)) if (string.IsNullOrEmpty(httpHomePath))
{ {
string host = Host; var host = Host;
if (host.StartsWith("ftp.")) if (host.StartsWith("ftp."))
{ {
host = host.Substring(4); host = host.Substring(4);
} }
path = URLHelpers.CombineURL(host, subFolderPath, filename); httpHomeUri = new UriBuilder(URLHelpers.CombineURL(host, subFolderPath, filename));
} }
else else
{ {
//Parse HttpHomePath in to host, port and path components
var firstSlash = httpHomePath.IndexOf('/');
var httpHome = firstSlash >= 0 ? httpHomePath.Substring(0, firstSlash) : httpHomePath;
var portSpecifiedAt = httpHome.LastIndexOf(':');
var httpHomeHost = portSpecifiedAt >= 0 ? httpHome.Substring(0, portSpecifiedAt) : httpHome;
var httpHomePort = -1;
var httpHomeDir = httpHomePath.Substring(firstSlash + 1);
if (portSpecifiedAt >= 0)
int.TryParse(httpHome.Substring(portSpecifiedAt + 1), out httpHomePort);
//Build URI
httpHomeUri = new UriBuilder {Host = httpHomeHost, Path = httpHomeDir};
if (portSpecifiedAt >= 0)
httpHomeUri.Port = httpHomePort;
if (HttpHomePathAutoAddSubFolderPath) if (HttpHomePathAutoAddSubFolderPath)
httpHomeUri.Path = URLHelpers.CombineURL(httpHomeUri.Path, subFolderPath);
if (httpHomeUri.Query.EndsWith("="))
{ {
path = URLHelpers.CombineURL(httpHomePath, subFolderPath); httpHomeUri.Query += filename;
} }
else else
{ {
path = httpHomePath; httpHomeUri.Path = URLHelpers.CombineURL(httpHomeUri.Path, filename);
}
if (path.EndsWith("="))
{
path += filename;
}
else
{
path = URLHelpers.CombineURL(path, filename);
} }
} }
string browserProtocol = BrowserProtocol.GetDescription(); httpHomeUri.Scheme = BrowserProtocol.GetDescription();
return httpHomeUri.Uri.ToString();
if (!path.StartsWith(browserProtocol))
{
path = browserProtocol + path;
}
return path;
} }
public string GetFtpPath(string filemame) public string GetFtpPath(string filemame)