aboutsummaryrefslogtreecommitdiff
path: root/src/rest.cpp
diff options
context:
space:
mode:
authorstickies-v <stickies-v@protonmail.com>2022-01-18 16:37:54 +0000
committerstickies-v <stickies-v@protonmail.com>2022-03-10 12:01:53 +0100
commitfff771ee864975cee8c831651239bac95503c37a (patch)
tree7cf1a82cb5442ee3ae7436cb5145305f49726b6d /src/rest.cpp
parentc1aad1b3b95b7c6bdf05e0c2095aba2f2db8310b (diff)
downloadbitcoin-fff771ee864975cee8c831651239bac95503c37a.tar.xz
Handle query string when parsing data format
URLs may contain a query string (prefixed with '?') and this should be ignored when parsing the data format. To facilitate testing this functionality, ParseDataFormat has been made non-static.
Diffstat (limited to 'src/rest.cpp')
-rw-r--r--src/rest.cpp23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/rest.cpp b/src/rest.cpp
index 4daf995b01..ec9295b283 100644
--- a/src/rest.cpp
+++ b/src/rest.cpp
@@ -135,23 +135,26 @@ static ChainstateManager* GetChainman(const std::any& context, HTTPRequest* req)
RESTResponseFormat ParseDataFormat(std::string& param, const std::string& strReq)
{
- const std::string::size_type pos = strReq.rfind('.');
- if (pos == std::string::npos)
- {
- param = strReq;
+ // Remove query string (if any, separated with '?') as it should not interfere with
+ // parsing param and data format
+ param = strReq.substr(0, strReq.rfind('?'));
+ const std::string::size_type pos_format{param.rfind('.')};
+
+ // No format string is found
+ if (pos_format == std::string::npos) {
return rf_names[0].rf;
}
- param = strReq.substr(0, pos);
- const std::string suff(strReq, pos + 1);
-
+ // Match format string to available formats
+ const std::string suffix(param, pos_format + 1);
for (const auto& rf_name : rf_names) {
- if (suff == rf_name.name)
+ if (suffix == rf_name.name) {
+ param.erase(pos_format);
return rf_name.rf;
+ }
}
- /* If no suffix is found, return original string. */
- param = strReq;
+ // If no suffix is found, return RESTResponseFormat::UNDEF and original string without query string
return rf_names[0].rf;
}