Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit da80324

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

File tree

Expand file treeCollapse file tree

1 file changed

+16
-12
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+16
-12
lines changed

‎src/ResourceResolver.cpp

Copy file name to clipboardExpand all lines: src/ResourceResolver.cpp
+16-12Lines 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)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.