Enhancements

Fix request parameters are url-decoded twice.
Fix post form request not handled correctly.
This commit is contained in:
Tindy X
2023-12-06 15:54:05 +08:00
parent 043c1fdcb9
commit 13623d6bcd
4 changed files with 14 additions and 14 deletions

View File

@@ -331,12 +331,12 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS)
readConf();
/// string values
std::string argUrl = urlDecode(getUrlArg(argument, "url"));
std::string argGroupName = urlDecode(getUrlArg(argument, "group")), argUploadPath = getUrlArg(argument, "upload_path");
std::string argIncludeRemark = urlDecode(getUrlArg(argument, "include")), argExcludeRemark = urlDecode(getUrlArg(argument, "exclude"));
std::string argCustomGroups = urlSafeBase64Decode(getUrlArg(argument, "groups")), argCustomRulesets = urlSafeBase64Decode(getUrlArg(argument, "ruleset")), argExternalConfig = urlDecode(getUrlArg(argument, "config"));
std::string argDeviceID = getUrlArg(argument, "dev_id"), argFilename = urlDecode(getUrlArg(argument, "filename")), argUpdateInterval = getUrlArg(argument, "interval"), argUpdateStrict = getUrlArg(argument, "strict");
std::string argRenames = urlDecode(getUrlArg(argument, "rename")), argFilterScript = urlDecode(getUrlArg(argument, "filter_script"));
std::string argUrl = getUrlArg(argument, "url");
std::string argGroupName = getUrlArg(argument, "group"), argUploadPath = getUrlArg(argument, "upload_path");
std::string argIncludeRemark = getUrlArg(argument, "include"), argExcludeRemark = getUrlArg(argument, "exclude");
std::string argCustomGroups = urlSafeBase64Decode(getUrlArg(argument, "groups")), argCustomRulesets = urlSafeBase64Decode(getUrlArg(argument, "ruleset")), argExternalConfig = getUrlArg(argument, "config");
std::string argDeviceID = getUrlArg(argument, "dev_id"), argFilename = getUrlArg(argument, "filename"), argUpdateInterval = getUrlArg(argument, "interval"), argUpdateStrict = getUrlArg(argument, "strict");
std::string argRenames = getUrlArg(argument, "rename"), argFilterScript = getUrlArg(argument, "filter_script");
/// switches with default value
tribool argUpload = getUrlArg(argument, "upload"), argEmoji = getUrlArg(argument, "emoji"), argAddEmoji = getUrlArg(argument, "add_emoji"), argRemoveEmoji = getUrlArg(argument, "remove_emoji");
@@ -701,7 +701,7 @@ std::string subconverter(RESPONSE_CALLBACK_ARGS)
ProxyGroupConfigs dummy_group;
std::vector<RulesetContent> dummy_ruleset;
std::string managed_url = base64Decode(urlDecode(getUrlArg(argument, "profile_data")));
std::string managed_url = base64Decode(getUrlArg(argument, "profile_data"));
if(managed_url.empty())
managed_url = global.managedConfigPrefix + "/sub?" + joinArguments(argument);
@@ -1160,7 +1160,7 @@ std::string getProfile(RESPONSE_CALLBACK_ARGS)
auto &argument = request.argument;
int *status_code = &response.status_code;
std::string name = urlDecode(getUrlArg(argument, "name")), token = urlDecode(getUrlArg(argument, "token"));
std::string name = getUrlArg(argument, "name"), token = getUrlArg(argument, "token");
string_array profiles = split(name, "|");
if(token.empty() || profiles.empty())
{
@@ -1440,7 +1440,7 @@ std::string renderTemplate(RESPONSE_CALLBACK_ARGS)
auto &argument = request.argument;
int *status_code = &response.status_code;
std::string path = urlDecode(getUrlArg(argument, "path"));
std::string path = getUrlArg(argument, "path");
writeLog(0, "Trying to render template '" + path + "'...", LOG_LEVEL_INFO);
if(!startsWith(path, global.templatePath) || !fileExist(path))

View File

@@ -52,7 +52,7 @@ static httplib::Server::Handler makeHandler(const responseRoute &rr)
req.argument = request.params;
if (request.get_header_value("Content-Type") == "application/x-www-form-urlencoded")
{
req.postdata = urlDecode(req.postdata);
req.postdata = urlDecode(request.body);
}
else
{

View File

@@ -343,10 +343,10 @@ std::string getUrlArg(const std::string &url, const std::string &request)
return "";
}
std::string getUrlArg(const string_multimap &url, const std::string &request)
std::string getUrlArg(const string_multimap &args, const std::string &request)
{
auto it = url.find(request);
if(it != url.end())
auto it = args.find(request);
if(it != args.end())
return it->second;
return "";
}

View File

@@ -31,7 +31,7 @@ std::string join(InputIt first, InputIt last, const std::string &delimiter)
}
std::string getUrlArg(const std::string &url, const std::string &request);
std::string getUrlArg(const string_multimap &url, const std::string &request);
std::string getUrlArg(const string_multimap &args, const std::string &request);
std::string replaceAllDistinct(std::string str, const std::string &old_value, const std::string &new_value);
std::string trimOf(const std::string& str, char target, bool before = true, bool after = true);
std::string trim(const std::string& str, bool before = true, bool after = true);