Skip to content

Commit 941d413

Browse files
author
Me No Dev
committed
fix urlDecode points
Fixes: esp8266#1989 esp8266#2198
1 parent 3cf75ca commit 941d413

File tree

1 file changed

+25
-18
lines changed

1 file changed

+25
-18
lines changed

libraries/ESP8266WebServer/src/Parsing.cpp

+25-18
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
9191
String searchStr = "";
9292
int hasSearch = url.indexOf('?');
9393
if (hasSearch != -1){
94-
searchStr = url.substring(hasSearch + 1);
94+
searchStr = urlDecode(url.substring(hasSearch + 1));
9595
url = url.substring(0, hasSearch);
9696
}
9797
_currentUri = url;
@@ -135,6 +135,7 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
135135
String headerName;
136136
String headerValue;
137137
bool isForm = false;
138+
bool isEncoded = false;
138139
uint32_t contentLength = 0;
139140
//parse headers
140141
while(1){
@@ -150,17 +151,20 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
150151
headerValue.trim();
151152
_collectHeader(headerName.c_str(),headerValue.c_str());
152153

153-
#ifdef DEBUG_ESP_HTTP_SERVER
154-
DEBUG_OUTPUT.print("headerName: ");
155-
DEBUG_OUTPUT.println(headerName);
156-
DEBUG_OUTPUT.print("headerValue: ");
157-
DEBUG_OUTPUT.println(headerValue);
158-
#endif
154+
#ifdef DEBUG_ESP_HTTP_SERVER
155+
DEBUG_OUTPUT.print("headerName: ");
156+
DEBUG_OUTPUT.println(headerName);
157+
DEBUG_OUTPUT.print("headerValue: ");
158+
DEBUG_OUTPUT.println(headerValue);
159+
#endif
159160

160161
if (headerName == "Content-Type"){
161162
if (headerValue.startsWith("text/plain")){
162163
isForm = false;
163-
} else if (headerValue.startsWith("multipart/form-data")){
164+
} else if (headerValue.startsWith("application/x-www-form-urlencoded")){
165+
isForm = false;
166+
isEncoded = true;
167+
} else if (headerValue.startsWith("multipart/")){
164168
boundaryStr = headerValue.substring(headerValue.indexOf('=')+1);
165169
isForm = true;
166170
}
@@ -178,19 +182,22 @@ bool ESP8266WebServer::_parseRequest(WiFiClient& client) {
178182
free(plainBuf);
179183
return false;
180184
}
181-
#ifdef DEBUG_ESP_HTTP_SERVER
182-
DEBUG_OUTPUT.print("Plain: ");
183-
DEBUG_OUTPUT.println(plainBuf);
184-
#endif
185185
if (contentLength > 0) {
186-
if (searchStr != "") searchStr += '&';
187-
if(plainBuf[0] == '{' || plainBuf[0] == '[' || strstr(plainBuf, "=") == NULL){
186+
if(isEncoded){
187+
//url encoded form
188+
String decoded = urlDecode(plainBuf);
189+
size_t decodedLen = decoded.length();
190+
memcpy(plainBuf, decoded.c_str(), decodedLen);
191+
plainBuf[decodedLen] = 0;
192+
} else {
188193
//plain post json or other data
189194
searchStr += "plain=";
190-
searchStr += plainBuf;
191-
} else {
192-
searchStr += plainBuf;
193195
}
196+
searchStr += plainBuf;
197+
#ifdef DEBUG_ESP_HTTP_SERVER
198+
DEBUG_OUTPUT.print("Plain: ");
199+
DEBUG_OUTPUT.println(plainBuf);
200+
#endif
194201
free(plainBuf);
195202
}
196203
}
@@ -303,7 +310,7 @@ void ESP8266WebServer::_parseArguments(String data) {
303310
}
304311
RequestArgument& arg = _currentArgs[iarg];
305312
arg.key = data.substring(pos, equal_sign_index);
306-
arg.value = urlDecode(data.substring(equal_sign_index + 1, next_arg_index));
313+
arg.value = data.substring(equal_sign_index + 1, next_arg_index);
307314
#ifdef DEBUG_ESP_HTTP_SERVER
308315
DEBUG_OUTPUT.print("arg ");
309316
DEBUG_OUTPUT.print(iarg);

0 commit comments

Comments
 (0)