8000 fix parseArgument by d-a-v · Pull Request #5230 · esp8266/Arduino · GitHub
[go: up one dir, main page]

Skip to content

fix parseArgument #5230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8000
Prev Previous commit
Next Next commit
remove recursion
  • Loading branch information
d-a-v committed Oct 11, 2018
commit aa4dac986ef316629d541f3128986be4b2a2f709
3 changes: 2 additions & 1 deletion libraries/ESP8266WebServer/src/ESP8266WebServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ class ESP8266WebServer
void _handleRequest();
void _finalizeResponse();
bool _parseRequest(WiFiClient& client);
int _parseArguments(const String& data, bool store = true);
void _parseArguments(const String& data);
int _parseArgumentsPrivate(const String& data, int counted);
static String _responseCodeToString(int code);
bool _parseForm(WiFiClient& client, String boundary, uint32_t len);
bool _parseFormUploadAborted();
Expand Down
25 changes: 13 additions & 12 deletions libraries/ESP8266WebServer/src/Parsing.cpp
4A2A
Original file line number Diff line number Diff line change
Expand Up @@ -270,26 +270,27 @@ bool ESP8266WebServer::_collectHeader(const char* headerName, const char* header
return false;
}

int ESP8266WebServer::_parseArguments(const String& data, bool store) {
// when store is true, a recursive call
// with store=false is recursively called first
// to evaluate the number of arguments
// should we use a vector instead?
void ESP8266WebServer::_parseArguments(const String& data) {
int counted = _parseArgumentsPrivate(data, 0);
(void)_parseArgumentsPrivate(data, counted);
}

int ESP8266WebServer::_parseArgumentsPrivate(const String& data, int counted) {
// counted==0: parsing only, return counted arguments
// counted!=0: parsing and storing "counted" arguments

#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("args: ");
DEBUG_OUTPUT.println(data);
#endif

if (store) {
if (counted > 0) {
if (_currentArgs)
delete[] _currentArgs;
_currentArgs = 0;
}

if (store) {
_currentArgCount = _parseArguments(data, false);
_currentArgs = new RequestArgument[_currentArgCount+1];
// allocate one more, this is needed (search "plainBuf" in this file)
_currentArgs = new RequestArgument[(_currentArgCount = counted) + 1];
}

size_t pos = 0;
Expand Down Expand Up @@ -319,7 +320,7 @@ int ESP8266WebServer::_parseArguments(const String& data, bool store) {
if (keyEndPos >= (int)pos) {
// do not store or count empty ending key ("url?x=y;")

if (store) {
if (counted > 0) {
RequestArgument& arg = _currentArgs[arg_total];
arg.key = urlDecode(data.substring(pos, keyEndPos));
if ((equal_index != -1) && ((equal_index < next_index - 1) || (next_index == -1)))
Expand Down Expand Up @@ -347,7 +348,7 @@ int ESP8266WebServer::_parseArguments(const String& data, bool store) {
DEBUG_OUTPUT.println(arg_total);
#endif

if (store)
if (counted > 0)
_currentArgCount = arg_total;

return arg_total;
Expand Down
0