mirror of
https://github.com/ShareX/ShareX.git
synced 2024-06-30 12:11:07 +12:00
Ignore emojis while URL encoding S3 result URL
This commit is contained in:
parent
ec610f32e0
commit
809283318f
|
@ -31,6 +31,21 @@ namespace ShareX.HelpersLib
|
|||
{
|
||||
public static class Emoji
|
||||
{
|
||||
public static int SearchEmoji(string text)
|
||||
{
|
||||
int emojiLength = 0;
|
||||
|
||||
foreach (string emoji in Emojis)
|
||||
{
|
||||
if (text.StartsWith(emoji, StringComparison.Ordinal))
|
||||
{
|
||||
emojiLength = Math.Max(emojiLength, emoji.Length);
|
||||
}
|
||||
}
|
||||
|
||||
return emojiLength;
|
||||
}
|
||||
|
||||
public static void SaveEmojiList(string filePath)
|
||||
{
|
||||
File.WriteAllText(filePath, string.Join(Environment.NewLine, Emojis), Encoding.UTF8);
|
||||
|
|
|
@ -115,6 +115,30 @@ public static string URLEncode(string text, bool isPath = false)
|
|||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static string URLEncodeIgnoreEmoji(string text, bool isPath = false)
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
|
||||
for (int i = 0; i < text.Length; i++)
|
||||
{
|
||||
string remainingText = text.Substring(i);
|
||||
|
||||
int emojiLength = Emoji.SearchEmoji(remainingText);
|
||||
|
||||
if (emojiLength > 0)
|
||||
{
|
||||
sb.Append(remainingText.Substring(0, emojiLength));
|
||||
i += emojiLength - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
sb.Append(URLEncode(remainingText.Substring(0, 1), isPath));
|
||||
}
|
||||
}
|
||||
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
public static string RemoveBidiControlCharacters(string text)
|
||||
{
|
||||
return new string(text.Where(c => !BidiControlCharacters.Contains(c)).ToArray());
|
||||
|
|
|
@ -263,7 +263,7 @@ public string GenerateURL(string uploadPath)
|
|||
{
|
||||
if (!string.IsNullOrEmpty(Settings.Endpoint) && !string.IsNullOrEmpty(Settings.Bucket))
|
||||
{
|
||||
uploadPath = URLHelpers.URLEncode(uploadPath, true);
|
||||
uploadPath = URLHelpers.URLEncodeIgnoreEmoji(uploadPath, true);
|
||||
|
||||
string url;
|
||||
|
||||
|
|
Loading…
Reference in a new issue