Implemented ability to URLencode data in Request and Parse blocks.

This commit is contained in:
ruri
2019-05-07 17:32:40 +02:00
parent 23a110620d
commit 6641a4c655
8 changed files with 48 additions and 19 deletions
+2 -1
View File
@@ -287,9 +287,10 @@ namespace RuriLib
/// <param name="variableName">The name of the variable to create</param>
/// <param name="prefix">The string to add at the start of the value</param>
/// <param name="suffix">The string to add at the end of the value</param>
public static void InsertVariables(BotData data, bool isCapture, bool recursive, List<string> values, string variableName, string prefix, string suffix)
public static void InsertVariables(BotData data, bool isCapture, bool recursive, List<string> values, string variableName, string prefix, string suffix, bool urlEncode)
{
var list = values.Select(v => ReplaceValues(prefix, data) + v.Trim() + ReplaceValues(suffix, data)).ToList();
if (urlEncode) list = list.Select(v => System.Uri.EscapeDataString(v)).ToList();
CVar variable;
if (recursive) variable = new CVar(variableName, list, isCapture);
else variable = new CVar(variableName, list.Count == 0 ? "" : list.First(), isCapture);
+1 -1
View File
@@ -690,7 +690,7 @@ namespace RuriLib
}
var isList = outputs.Count > 1 || InputString.Contains("[*]") || InputString.Contains("(*)") || InputString.Contains("{*}");
InsertVariables(data, isCapture, isList, outputs, variableName, "", "");
InsertVariables(data, isCapture, isList, outputs, variableName, "", "", false);
}
#region Base64
+15 -5
View File
@@ -59,6 +59,10 @@ namespace RuriLib
/// <summary>Whether to parse multiple values that match the criteria or just the first one.</summary>
public bool Recursive { get { return recursive; } set { recursive = value; OnPropertyChanged(); } }
private bool encodeOutput = false;
/// <summary>Whether to URL encode the parsed text.</summary>
public bool EncodeOutput { get { return encodeOutput; } set { encodeOutput = value; OnPropertyChanged(); } }
private ParseType type = ParseType.LR;
/// <summary>The parsing algorithm being used.</summary>
public ParseType Type { get { return type; } set { type = value; OnPropertyChanged(); } }
@@ -147,12 +151,14 @@ namespace RuriLib
LineParser.SetBool(ref input, this);
else if (LineParser.Lookahead(ref input) == TokenType.Integer)
CssElementIndex = LineParser.ParseInt(ref input, "INDEX");
if (LineParser.Lookahead(ref input) == TokenType.Boolean)
LineParser.SetBool(ref input, this);
break;
case ParseType.JSON:
// PARSE "<SOURCE>" JSON "Field" ->
JsonField = LineParser.ParseLiteral(ref input, "FIELD");
if (LineParser.Lookahead(ref input) == TokenType.Boolean)
while (LineParser.Lookahead(ref input) == TokenType.Boolean)
LineParser.SetBool(ref input, this);
break;
@@ -160,7 +166,7 @@ namespace RuriLib
// PARSE "<SOURCE>" REGEX "Pattern" "Output" RECURSIVE? ->
RegexString = LineParser.ParseLiteral(ref input, "PATTERN");
RegexOutput = LineParser.ParseLiteral(ref input, "OUTPUT");
if (LineParser.Lookahead(ref input) == TokenType.Boolean)
while (LineParser.Lookahead(ref input) == TokenType.Boolean)
LineParser.SetBool(ref input, this);
break;
}
@@ -209,6 +215,7 @@ namespace RuriLib
.Literal(LeftString)
.Literal(RightString)
.Boolean(Recursive, "Recursive")
.Boolean(EncodeOutput, "EncodeOutput")
.Boolean(UseRegexLR, "UseRegexLR");
break;
@@ -218,19 +225,22 @@ namespace RuriLib
.Literal(AttributeName);
if (Recursive) writer.Boolean(Recursive, "Recursive");
else writer.Integer(CssElementIndex, "CssElementIndex");
writer.Boolean(EncodeOutput, "EncodeOutput");
break;
case ParseType.JSON:
writer
.Literal(JsonField)
.Boolean(Recursive, "Recursive");
.Boolean(Recursive, "Recursive")
.Boolean(EncodeOutput, "EncodeOutput");
break;
case ParseType.REGEX:
writer
.Literal(RegexString)
.Literal(RegexOutput)
.Boolean(Recursive, "Recursive");
.Boolean(Recursive, "Recursive")
.Boolean(EncodeOutput, "EncodeOutput");
break;
}
@@ -250,7 +260,7 @@ namespace RuriLib
{
base.Process(data);
InsertVariables(data, isCapture, recursive, Parse(data), variableName, prefix, suffix);
InsertVariables(data, isCapture, recursive, Parse(data), variableName, prefix, suffix, encodeOutput);
}
private List<string> Parse(BotData data)
+6
View File
@@ -107,6 +107,10 @@ namespace RuriLib
/// <summary>Whether to parse the GET parameters manually (fixes Extreme.NET issues on some websites).</summary>
public bool ParseQuery { get { return parseQuery; } set { parseQuery = value; OnPropertyChanged(); } }
private bool encodeContent = false;
/// <summary>Whether to URL encode the content before sending it.</summary>
public bool EncodeContent { get { return encodeContent; } set { encodeContent = value; OnPropertyChanged(); } }
// Multipart
private string multipartBoundary = "";
/// <summary>The boundary that separates multipart contents.</summary>
@@ -252,6 +256,7 @@ namespace RuriLib
.Boolean(AutoRedirect, "AutoRedirect")
.Boolean(ReadResponseSource, "ReadResponseSource")
.Boolean(ParseQuery, "ParseQuery")
.Boolean(EncodeContent, "EncodeContent")
.Token(RequestType, "RequestType")
.Indent();
@@ -387,6 +392,7 @@ namespace RuriLib
.Select(p => ReplaceValues(p, data)));
if (pData != "")
{
if (encodeContent) pData = System.Uri.EscapeDataString(pData);
content = new StringContent(pData);
content.ContentType = cType;
data.Log(new LogEntry(string.Format("Post Data: {0}", pData), Colors.MediumTurquoise));