mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-30 01:07:21 +13:00
Remove bidirectional control characters from file name before upload
This commit is contained in:
parent
c5f24df681
commit
55be475017
3 changed files with 15 additions and 5 deletions
|
@ -59,9 +59,6 @@ public static class Helpers
|
|||
public const string Alphanumeric = Numbers + AlphabetCapital + Alphabet;
|
||||
public const string AlphanumericInverse = Numbers + Alphabet + AlphabetCapital;
|
||||
public const string Hexadecimal = Numbers + "ABCDEF";
|
||||
public const string URLCharacters = Alphanumeric + "-._~"; // 45 46 95 126
|
||||
public const string URLPathCharacters = URLCharacters + "/"; // 47
|
||||
public const string ValidURLCharacters = URLPathCharacters + ":?#[]@!$&'()*+,;= ";
|
||||
|
||||
public static readonly string[] ImageFileExtensions = new string[] { "jpg", "jpeg", "png", "gif", "bmp", "ico", "tif", "tiff" };
|
||||
public static readonly string[] TextFileExtensions = new string[] { "txt", "log", "nfo", "c", "cpp", "cc", "cxx", "h", "hpp", "hxx", "cs", "vb", "html", "htm", "xhtml", "xht", "xml", "css", "js", "php", "bat", "java", "lua", "py", "pl", "cfg", "ini", "dart", "go", "gohtml" };
|
||||
|
|
|
@ -36,6 +36,12 @@ namespace ShareX.HelpersLib
|
|||
{
|
||||
public static class URLHelpers
|
||||
{
|
||||
public const string URLCharacters = Helpers.Alphanumeric + "-._~"; // 45 46 95 126
|
||||
public const string URLPathCharacters = URLCharacters + "/"; // 47
|
||||
public const string ValidURLCharacters = URLPathCharacters + ":?#[]@!$&'()*+,;= ";
|
||||
|
||||
public static readonly char[] BidiControlCharacters = new char[] { '\u200E', '\u200F', '\u202A', '\u202B', '\u202C', '\u202D', '\u202E' };
|
||||
|
||||
public static void OpenURL(string url)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(url))
|
||||
|
@ -73,11 +79,11 @@ public static string URLEncode(string text, bool isPath = false)
|
|||
|
||||
if (isPath)
|
||||
{
|
||||
unreservedCharacters = Helpers.URLPathCharacters;
|
||||
unreservedCharacters = URLPathCharacters;
|
||||
}
|
||||
else
|
||||
{
|
||||
unreservedCharacters = Helpers.URLCharacters;
|
||||
unreservedCharacters = URLCharacters;
|
||||
}
|
||||
|
||||
foreach (char c in Encoding.UTF8.GetBytes(text))
|
||||
|
@ -96,6 +102,11 @@ public static string URLEncode(string text, bool isPath = false)
|
|||
return result.ToString();
|
||||
}
|
||||
|
||||
public static string RemoveBidiControlCharacters(string text)
|
||||
{
|
||||
return new string(text.Where(c => !BidiControlCharacters.Contains(c)).ToArray());
|
||||
}
|
||||
|
||||
public static string HtmlEncode(string text)
|
||||
{
|
||||
char[] chars = HttpUtility.HtmlEncode(text).ToCharArray();
|
||||
|
|
|
@ -853,6 +853,8 @@ public UploadResult UploadData(IGenericUploaderService service, Stream stream, s
|
|||
uploader.EarlyURLCopyRequested += url => ClipboardHelpers.CopyText(url);
|
||||
}
|
||||
|
||||
fileName = URLHelpers.RemoveBidiControlCharacters(fileName);
|
||||
|
||||
if (Info.TaskSettings.UploadSettings.FileUploadReplaceProblematicCharacters)
|
||||
{
|
||||
// http://www.ietf.org/rfc/rfc3986.txt
|
||||
|
|
Loading…
Reference in a new issue