Skip to content

Commit

Permalink
Merge pull request esp8266#1069 from joostjager/master
Browse files Browse the repository at this point in the history
Url decode added for search parameters
  • Loading branch information
igrr committed Nov 25, 2015
2 parents 866921c + ac8cfa0 commit 14bd3d9
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
1 change: 1 addition & 0 deletions libraries/ESP8266WebServer/src/ESP8266WebServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ template<typename T> size_t streamFile(T &file, const String& contentType){
uint8_t _uploadReadByte(WiFiClient& client);
void _prepareHeader(String& response, int code, const char* content_type, size_t contentLength);
bool _collectHeader(const char* headerName, const char* headerValue);
String urlDecode(const String& text);

struct RequestArgument {
String key;
Expand Down
33 changes: 32 additions & 1 deletion libraries/ESP8266WebServer/src/Parsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ void ESP8266WebServer::_parseArguments(String data) {
}
RequestArgument& arg = _currentArgs[iarg];
arg.key = data.substring(pos, equal_sign_index);
arg.value = data.substring(equal_sign_index + 1, next_arg_index);
arg.value = urlDecode(data.substring(equal_sign_index + 1, next_arg_index));
#ifdef DEBUG
DEBUG_OUTPUT.print("arg ");
DEBUG_OUTPUT.print(iarg);
Expand Down Expand Up @@ -513,6 +513,37 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
return false;
}

String ESP8266WebServer::urlDecode(const String& text)
{
String decoded = "";
char temp[] = "0x00";
unsigned int len = text.length();
unsigned int i = 0;
while (i < len)
{
char decodedChar;
char encodedChar = text.charAt(i++);
if ((encodedChar == '%') && (i + 1 < len))
{
temp[2] = text.charAt(i++);
temp[3] = text.charAt(i++);

decodedChar = strtol(temp, NULL, 16);
}
else {
if (encodedChar == '+')
{
decodedChar = ' ';
}
else {
decodedChar = encodedChar; // normal ascii char
}
}
decoded += decodedChar;
}
return decoded;
}

bool ESP8266WebServer::_parseFormUploadAborted(){
_currentUpload.status = UPLOAD_FILE_ABORTED;
if(_currentHandler && _currentHandler->canUpload(_currentUri))
Expand Down

0 comments on commit 14bd3d9

Please sign in to comment.