Skip to content

Commit 6855dae

Browse files
committed
Fix URL parameter decoding in web server
The parameters string needs to be first split on & and =, and URL decoding on parts done after that. Otherwise URL encoded & and = within parameter names and values cause incorrect splitting.
1 parent 1adf577 commit 6855dae

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

libraries/ESP8266WebServer/src/Parsing.cpp

+2-6
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,9 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
186186
return false;
187187
}
188188
if (contentLength > 0) {
189-
if (searchStr != "") searchStr += '&';
190189
if(isEncoded){
191190
//url encoded form
192-
String decoded = urlDecode(plainBuf);
193-
size_t decodedLen = decoded.length();
194-
memcpy(plainBuf, decoded.c_str(), decodedLen);
195-
plainBuf[decodedLen] = 0;
191+
if (searchStr != "") searchStr += '&';
196192
searchStr += plainBuf;
197193
}
198194
_parseArguments(searchStr);
@@ -323,7 +319,7 @@ void ESP8266WebServer::_parseArguments(String data) {
323319
continue;
324320
}
325321
RequestArgument& arg = _currentArgs[iarg];
326-
arg.key = data.substring(pos, equal_sign_index);
322+
arg.key = urlDecode(data.substring(pos, equal_sign_index));
327323
arg.value = urlDecode(data.substring(equal_sign_index + 1, next_arg_index));
328324
#ifdef DEBUG_ESP_HTTP_SERVER
329325
DEBUG_OUTPUT.print("arg ");

0 commit comments

Comments
 (0)