Skip to content

Commit 34fcc91

Browse files
author
Joost Jager
committed
Url decode added for search parameters
1 parent 4b8fb20 commit 34fcc91

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
@@ -132,6 +132,7 @@ template<typename T> size_t streamFile(T &file, const String& contentType){
132132
uint8_t _uploadReadByte(WiFiClient& client);
133133
void _prepareHeader(String& response, int code, const char* content_type, size_t contentLength);
134134
bool _collectHeader(const char* headerName, const char* headerValue);
135+
String urlDecode(const String& text);
135136

136137
struct RequestArgument {
137138
String key;

libraries/ESP8266WebServer/src/Parsing.cpp

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ void ESP8266WebServer::_parseArguments(String data) {
255255
}
256256
RequestArgument& arg = _currentArgs[iarg];
257257
arg.key = data.substring(pos, equal_sign_index);
258-
arg.value = data.substring(equal_sign_index + 1, next_arg_index);
258+
arg.value = urlDecode(data.substring(equal_sign_index + 1, next_arg_index));
259259
#ifdef DEBUG
260260
DEBUG_OUTPUT.print("arg ");
261261
DEBUG_OUTPUT.print(iarg);
@@ -501,6 +501,37 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
501501
return false;
502502
}
503503

504+
String ESP8266WebServer::urlDecode(const String& text)
505+
{
506+
String decoded = "";
507+
char temp[] = "0x00";
508+
unsigned int len = text.length();
509+
unsigned int i = 0;
510+
while (i < len)
511+
{
512+
char decodedChar;
513+
char encodedChar = text.charAt(i++);
514+
if ((encodedChar == '%') && (i + 1 < len))
515+
{
516+
temp[2] = text.charAt(i++);
517+
temp[3] = text.charAt(i++);
518+
519+
decodedChar = strtol(temp, NULL, 16);
520+
}
521+
else {
522+
if (encodedChar == '+')
523+
{
524+
decodedChar = ' ';
525+
}
526+
else {
527+
decodedChar = encodedChar; // normal ascii char
528+
}
529+
}
530+
decoded += decodedChar;
531+
}
532+
return decoded;
533+
}
534+
504535
bool ESP8266WebServer::_parseFormUploadAborted(){
505536
_currentUpload.status = UPLOAD_FILE_ABORTED;
506537
if (_fileUploadHandler) _fileUploadHandler();

0 commit comments

Comments
 (0)