mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-29 17:02:05 +13:00
Make sure DownloadAndUpload task creates valid filename
This commit is contained in:
parent
9933cf8110
commit
3ce053da36
2 changed files with 20 additions and 15 deletions
|
@ -27,7 +27,6 @@ You should have received a copy of the GNU General Public License
|
|||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
|
@ -123,6 +122,19 @@ public static string HtmlEncode(string text)
|
|||
return result.ToString();
|
||||
}
|
||||
|
||||
public static string URLDecode(string url, int count = 1)
|
||||
{
|
||||
string temp = null;
|
||||
|
||||
for (int i = 0; i < count && url != temp; i++)
|
||||
{
|
||||
temp = url;
|
||||
url = HttpUtility.UrlDecode(url);
|
||||
}
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
public static string CombineURL(string url1, string url2)
|
||||
{
|
||||
bool url1Empty = string.IsNullOrEmpty(url1);
|
||||
|
@ -251,19 +263,8 @@ public static string AddSlash(string url, SlashType slashType, int count)
|
|||
return url;
|
||||
}
|
||||
|
||||
public static string GetFileName(string path, bool urlDecode = false)
|
||||
public static string GetFileName(string path)
|
||||
{
|
||||
if (urlDecode)
|
||||
{
|
||||
string tempPath = null;
|
||||
|
||||
for (int i = 0; i < 10 && path != tempPath; i++)
|
||||
{
|
||||
tempPath = path;
|
||||
path = HttpUtility.UrlDecode(path);
|
||||
}
|
||||
}
|
||||
|
||||
if (path.Contains('/'))
|
||||
{
|
||||
path = path.Substring(path.LastIndexOf('/') + 1);
|
||||
|
|
|
@ -191,13 +191,17 @@ public static WorkerTask CreateDownloadUploadTask(string url, TaskSettings taskS
|
|||
WorkerTask task = new WorkerTask(taskSettings);
|
||||
task.Info.Job = TaskJob.DownloadUpload;
|
||||
task.Info.DataType = TaskHelpers.FindDataType(url, taskSettings);
|
||||
task.Info.FileName = URLHelpers.GetFileName(url, true);
|
||||
|
||||
if (string.IsNullOrEmpty(task.Info.FileName))
|
||||
string filename = URLHelpers.URLDecode(url, 10);
|
||||
filename = URLHelpers.GetFileName(filename);
|
||||
filename = Helpers.GetValidFileName(filename);
|
||||
|
||||
if (string.IsNullOrEmpty(filename))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
task.Info.FileName = filename;
|
||||
task.Info.Result.URL = url;
|
||||
return task;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue