forked from me-no-dev/ESPAsyncWebServer
expose urlDecode to the masses
This commit is contained in:
@@ -121,7 +121,6 @@ class AsyncWebServerRequest {
|
|||||||
void _onData(void *buf, size_t len);
|
void _onData(void *buf, size_t len);
|
||||||
|
|
||||||
void _addParam(AsyncWebParameter*);
|
void _addParam(AsyncWebParameter*);
|
||||||
String _urlDecode(const String& text);
|
|
||||||
|
|
||||||
bool _parseReqHead();
|
bool _parseReqHead();
|
||||||
bool _parseReqHeader();
|
bool _parseReqHeader();
|
||||||
@@ -190,6 +189,7 @@ class AsyncWebServerRequest {
|
|||||||
String headerName(int i); // get request header name by number
|
String headerName(int i); // get request header name by number
|
||||||
bool hasHeader(const char* name); // check if header exists
|
bool hasHeader(const char* name); // check if header exists
|
||||||
|
|
||||||
|
String urlDecode(const String& text);
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@@ -38,5 +38,3 @@ void AsyncStaticWebHandler::handleRequest(AsyncWebServerRequest *request){
|
|||||||
request->send(404);
|
request->send(404);
|
||||||
path = String();
|
path = String();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@@ -173,7 +173,7 @@ void AsyncWebServerRequest::_addParam(AsyncWebParameter *p){
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AsyncWebServerRequest::_addGetParam(String param){
|
void AsyncWebServerRequest::_addGetParam(String param){
|
||||||
param = _urlDecode(param);
|
param = urlDecode(param);
|
||||||
String name = param;
|
String name = param;
|
||||||
String value = "";
|
String value = "";
|
||||||
if(param.indexOf('=') > 0){
|
if(param.indexOf('=') > 0){
|
||||||
@@ -277,7 +277,7 @@ void AsyncWebServerRequest::_parsePlainPostChar(uint8_t data){
|
|||||||
if(data && (char)data != '&')
|
if(data && (char)data != '&')
|
||||||
_temp += (char)data;
|
_temp += (char)data;
|
||||||
if(!data || (char)data == '&' || _parsedLength == _contentLength){
|
if(!data || (char)data == '&' || _parsedLength == _contentLength){
|
||||||
_temp = _urlDecode(_temp);
|
_temp = urlDecode(_temp);
|
||||||
String name = "body";
|
String name = "body";
|
||||||
String value = _temp;
|
String value = _temp;
|
||||||
if(!_temp.startsWith("{") && !_temp.startsWith("[") && _temp.indexOf('=') > 0){
|
if(!_temp.startsWith("{") && !_temp.startsWith("[") && _temp.indexOf('=') > 0){
|
||||||
@@ -440,7 +440,7 @@ void AsyncWebServerRequest::_parseMultipartPostByte(uint8_t data, bool last){
|
|||||||
}
|
}
|
||||||
} else if(_multiParseState == DASH3_OR_RETURN2){
|
} else if(_multiParseState == DASH3_OR_RETURN2){
|
||||||
if(data == '-' && (_contentLength - _parsedLength - 4) != 0){
|
if(data == '-' && (_contentLength - _parsedLength - 4) != 0){
|
||||||
os_printf("ERROR: The parser got to the end of the POST but is expecting % bytes more!\nDrop an issue so we can have more info on the matter!\n", _contentLength - _parsedLength - 4);
|
os_printf("ERROR: The parser got to the end of the POST but is expecting %u bytes more!\nDrop an issue so we can have more info on the matter!\n", _contentLength - _parsedLength - 4);
|
||||||
_contentLength = _parsedLength + 4;//lets close the request gracefully
|
_contentLength = _parsedLength + 4;//lets close the request gracefully
|
||||||
}
|
}
|
||||||
if(data == '\r'){
|
if(data == '\r'){
|
||||||
@@ -728,28 +728,23 @@ bool AsyncWebServerRequest::hasHeader(const char* name){
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String AsyncWebServerRequest::_urlDecode(const String& text){
|
String AsyncWebServerRequest::urlDecode(const String& text){
|
||||||
String decoded = "";
|
String decoded = "";
|
||||||
char temp[] = "0x00";
|
char temp[] = "0x00";
|
||||||
unsigned int len = text.length();
|
unsigned int len = text.length();
|
||||||
unsigned int i = 0;
|
unsigned int i = 0;
|
||||||
while (i < len)
|
while (i < len){
|
||||||
{
|
|
||||||
char decodedChar;
|
char decodedChar;
|
||||||
char encodedChar = text.charAt(i++);
|
char encodedChar = text.charAt(i++);
|
||||||
if ((encodedChar == '%') && (i + 1 < len))
|
if ((encodedChar == '%') && (i + 1 < len)){
|
||||||
{
|
|
||||||
temp[2] = text.charAt(i++);
|
temp[2] = text.charAt(i++);
|
||||||
temp[3] = text.charAt(i++);
|
temp[3] = text.charAt(i++);
|
||||||
|
|
||||||
decodedChar = strtol(temp, NULL, 16);
|
decodedChar = strtol(temp, NULL, 16);
|
||||||
}
|
} else {
|
||||||
else {
|
if (encodedChar == '+'){
|
||||||
if (encodedChar == '+')
|
|
||||||
{
|
|
||||||
decodedChar = ' ';
|
decodedChar = ' ';
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
decodedChar = encodedChar; // normal ascii char
|
decodedChar = encodedChar; // normal ascii char
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user