8000 Fix handling of empty query parameters, do url-decode query parameter… · MauAbata/esp32_https_server@da80324 · GitHub
[go: up one dir, main page]

Skip to content
8000

Commit da80324

Browse files
committed
Fix handling of empty query parameters, do url-decode query parameter names
1 parent 85e6c29 commit da80324

File tree

1 file changed

+16
-12
lines changed

1 file changed

+16
-12
lines changed

src/ResourceResolver.cpp

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -51,21 +51,25 @@ void ResourceResolver::resolveNode(const std::string &method, const std::string
5151
size_t nextparamIdx = url.find('&', reqparamIdx);
5252

5353
// Get the "name=value" string
54-
std::string param = url.substr(reqparamIdx, nextparamIdx - reqparamIdx);
55-
56-
// Find the position where the string has to be split
57-
size_t nvSplitIdx = param.find('=');
54+
std::string param = nextparamIdx == std::string::npos ?
55+
url.substr(reqparamIdx) :
56+
url.substr(reqparamIdx, nextparamIdx - reqparamIdx);
57+
58+
if (param.length() > 0) {
59+
// Find the position where the string has to be split
60+
size_t nvSplitIdx = param.find('=');
61+
62+
// Use empty string if only name is set. /foo?bar&baz=1 will return "" for bar
63+
std::string name = urlDecode(param.substr(0, nvSplitIdx));
64+
std::string value = "";
65+
if (nvSplitIdx != std::string::npos) {
66+
value = urlDecode(param.substr(nvSplitIdx+1));
67+
}
5868

59-
// Use empty string if only name is set. /foo?bar&baz=1 will return "" for bar
60-
std::string name = param.substr(0, nvSplitIdx);
61-
std::string value = "";
62-
if (nvSplitIdx != std::string::npos) {
63-
value = urlDecode(param.substr(nvSplitIdx+1));
69+
// Now we finally have name and value.
70+
params->setQueryParameter(name, value);
6471
}
6572

66-
// Now we finally have name and value.
67-
params->setQueryParameter(name, value);
68-
6973
// Update reqparamIdx
7074
reqparamIdx = nextparamIdx;
7175

0 commit comments

Comments
 (0)
0