Added support to escape custom uploader argument and header patterns

This commit is contained in:
Jaex 2018-03-26 08:04:55 +03:00
parent 8ff0461eea
commit ffe3949769
3 changed files with 58 additions and 1 deletions

View file

@ -41,7 +41,10 @@ public CustomUploaderArgumentInput(string filename, string input)
public string Parse(string arg)
{
arg = NameParser.Parse(NameParserType.Text, arg);
NameParser nameParser = new NameParser(NameParserType.Text);
EscapeHelper escapeHelper = new EscapeHelper();
arg = escapeHelper.Parse(arg, nameParser.Parse);
arg = arg.BatchReplace(new Dictionary<string, string>()
{

View file

@ -0,0 +1,53 @@
#region License Information (GPL v3)
/*
ShareX - A program that allows you to take screenshots and share any file type
Copyright (c) 2007-2018 ShareX Team
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
*/
#endregion License Information (GPL v3)
using ShareX.HelpersLib;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace ShareX.UploadersLib
{
public class EscapeHelper
{
public string EscapeCharacter { get; set; } = @"\";
public string EscapeableCharacter { get; set; } = "%";
private string escapeCharacterReserve = Helpers.GetRandomAlphanumeric(32);
private string escapeableCharacterReserve = Helpers.GetRandomAlphanumeric(32);
public string Parse(string input, Func<string, string> action)
{
input = input.Replace(EscapeCharacter + EscapeCharacter, escapeCharacterReserve);
input = input.Replace(EscapeCharacter + EscapeableCharacter, escapeableCharacterReserve);
input = action(input);
input = input.Replace(escapeableCharacterReserve, EscapeableCharacter);
input = input.Replace(escapeCharacterReserve, EscapeCharacter);
return input;
}
}
}

View file

@ -238,6 +238,7 @@
<Compile Include="FileUploaders\Pushbullet.cs" />
<Compile Include="FileUploaders\GfycatUploader.cs" />
<Compile Include="Helpers\CustomUploaderArgumentInput.cs" />
<Compile Include="Helpers\EscapeHelper.cs" />
<Compile Include="Helpers\OAuth\IOAuthBase.cs" />
<Compile Include="Helpers\SSLBypassHelper.cs" />
<Compile Include="BaseServices\URLSharingService.cs" />