Skip to content

Commit 14bd3d9

Browse files
committed
Merge pull request #1069 from joostjager/master
Url decode added for search parameters
2 parents 866921c + ac8cfa0 commit 14bd3d9

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

libraries/ESP8266WebServer/src/ESP8266WebServer.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ template<typename T> size_t streamFile(T &file, const String& contentType){
133133
uint8_t _uploadReadByte(WiFiClient& client);
134134
void _prepareHeader(String& response, int code, const char* content_type, size_t contentLength);
135135
bool _collectHeader(const char* headerName, const char* headerValue);
136+
String urlDecode(const String& text);
136137

137138
struct RequestArgument {
138139
String key;

libraries/ESP8266WebServer/src/Parsing.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ void ESP8266WebServer::_parseArguments(String data) {
263263
}
264264
RequestArgument& arg = _currentArgs[iarg];
265265
arg.key = data.substring(pos, equal_sign_index);
266-
arg.value = data.substring(equal_sign_index + 1, next_arg_index);
266+
arg.value = urlDecode(data.substring(equal_sign_index + 1, next_arg_index));
267267
#ifdef DEBUG
268268
DEBUG_OUTPUT.print("arg ");
269269
DEBUG_OUTPUT.print(iarg);
@@ -513,6 +513,37 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
513513
return false;
514514
}
515515

516+
String ESP8266WebServer::urlDecode(const String& text)
517+
{
518+
String decoded = "";
519+
char temp[] = "0x00";
520+
unsigned int len = text.length();
521+
unsigned int i = 0;
522+
while (i < len)
523+
{
524+
char decodedChar;
525+
char encodedChar = text.charAt(i++);
526+
if ((encodedChar == '%') && (i + 1 < len))
527+
{
528+
temp[2] = text.charAt(i++);
529+
temp[3] = text.charAt(i++);
530+
531+
decodedChar = strtol(temp, NULL, 16);
532+
}
533+
else {
534+
if (encodedChar == '+')
535+
{
536+
decodedChar = ' ';
537+
}
538+
else {
539+
decodedChar = encodedChar; // normal ascii char
540+
}
541+
}
542+
decoded += decodedChar;
543+
}
544+
return decoded;
545+
}
546+
516547
bool ESP8266WebServer::_parseFormUploadAborted(){
517548
_currentUpload.status = UPLOAD_FILE_ABORTED;
518549
if(_currentHandler && _currentHandler->canUpload(_currentUri))

0 commit comments

Comments
 (0)