mirror of
https://github.com/Jackett/Jackett
synced 2025-02-25 07:32:38 +00:00
Cardigann: properly encode variables in search path and $raw
This commit is contained in:
parent
65a4ca60cf
commit
0d8c446b74
1 changed files with 15 additions and 6 deletions
|
@ -267,7 +267,8 @@ namespace Jackett.Indexers
|
||||||
|
|
||||||
// A very bad implementation of the golang template/text templating engine.
|
// A very bad implementation of the golang template/text templating engine.
|
||||||
// But it should work for most basic constucts used by Cardigann definitions.
|
// But it should work for most basic constucts used by Cardigann definitions.
|
||||||
protected string applyGoTemplateText(string template, Dictionary<string, object> variables = null)
|
protected delegate string TemplateTextModifier(string str);
|
||||||
|
protected string applyGoTemplateText(string template, Dictionary<string, object> variables = null, TemplateTextModifier modifier = null)
|
||||||
{
|
{
|
||||||
if (variables == null)
|
if (variables == null)
|
||||||
{
|
{
|
||||||
|
@ -290,6 +291,9 @@ namespace Jackett.Indexers
|
||||||
var input = (string)variables[variable];
|
var input = (string)variables[variable];
|
||||||
var expanded = ReplaceRegex.Replace(input, newvalue);
|
var expanded = ReplaceRegex.Replace(input, newvalue);
|
||||||
|
|
||||||
|
if (modifier != null)
|
||||||
|
expanded = modifier(expanded);
|
||||||
|
|
||||||
template = template.Replace(all, expanded);
|
template = template.Replace(all, expanded);
|
||||||
ReReplaceRegexMatches = ReReplaceRegexMatches.NextMatch();
|
ReReplaceRegexMatches = ReReplaceRegexMatches.NextMatch();
|
||||||
}
|
}
|
||||||
|
@ -342,7 +346,10 @@ namespace Jackett.Indexers
|
||||||
|
|
||||||
foreach (string value in (List<string>)variables[variable])
|
foreach (string value in (List<string>)variables[variable])
|
||||||
{
|
{
|
||||||
expanded += prefix + value + postfix;
|
var newvalue = value;
|
||||||
|
if (modifier != null)
|
||||||
|
newvalue = modifier(newvalue);
|
||||||
|
expanded += prefix + newvalue + postfix;
|
||||||
}
|
}
|
||||||
template = template.Replace(all, expanded);
|
template = template.Replace(all, expanded);
|
||||||
RangeRegexMatches = RangeRegexMatches.NextMatch();
|
RangeRegexMatches = RangeRegexMatches.NextMatch();
|
||||||
|
@ -360,6 +367,8 @@ namespace Jackett.Indexers
|
||||||
string variable = VariablesRegExMatches.Groups[1].Value;
|
string variable = VariablesRegExMatches.Groups[1].Value;
|
||||||
|
|
||||||
string value = (string)variables[variable];
|
string value = (string)variables[variable];
|
||||||
|
if (modifier != null)
|
||||||
|
value = modifier(value);
|
||||||
template = template.Replace(all, value);
|
template = template.Replace(all, value);
|
||||||
VariablesRegExMatches = VariablesRegExMatches.NextMatch();
|
VariablesRegExMatches = VariablesRegExMatches.NextMatch();
|
||||||
}
|
}
|
||||||
|
@ -1029,17 +1038,17 @@ namespace Jackett.Indexers
|
||||||
variables[".Keywords"] = applyFilters((string)variables[".Query.Keywords"], Search.Keywordsfilters);
|
variables[".Keywords"] = applyFilters((string)variables[".Query.Keywords"], Search.Keywordsfilters);
|
||||||
|
|
||||||
// build search URL
|
// build search URL
|
||||||
var searchUrl = resolvePath(applyGoTemplateText(Search.Path, variables) + "?").ToString();
|
// HttpUtility.UrlPathEncode seems to only encode spaces, we use UrlEncode and replace + with %20 as a workaround
|
||||||
|
var searchUrl = resolvePath(applyGoTemplateText(Search.Path, variables, HttpUtility.UrlEncode).Replace("+", "%20") + "?").AbsoluteUri;
|
||||||
var queryCollection = new NameValueCollection();
|
var queryCollection = new NameValueCollection();
|
||||||
if (Search.Inputs != null)
|
if (Search.Inputs != null)
|
||||||
{
|
{
|
||||||
foreach (var Input in Search.Inputs)
|
foreach (var Input in Search.Inputs)
|
||||||
{
|
{
|
||||||
var value = applyGoTemplateText(Input.Value, variables);
|
|
||||||
if (Input.Key == "$raw")
|
if (Input.Key == "$raw")
|
||||||
searchUrl += value;
|
searchUrl += applyGoTemplateText(Input.Value, variables, HttpUtility.UrlEncode);
|
||||||
else
|
else
|
||||||
queryCollection.Add(Input.Key, value);
|
queryCollection.Add(Input.Key, applyGoTemplateText(Input.Value, variables));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (queryCollection.Count > 0)
|
if (queryCollection.Count > 0)
|
||||||
|
|
Loading…
Reference in a new issue