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

Skip to content

fix parseArgument #2 #5252

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

Merged
merged 17 commits into from
Oct 17, 2018
Merged
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
Prev Previous commit
Next Next commit
cleaning
  • Loading branch information
d-a-v committed Oct 16, 2018
commit 2cea06cf377b8ebc4938b9bc6f031dab8d74c70c
19 changes: 9 additions & 10 deletions libraries/ESP8266WebServer/src/Parsing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,10 @@ struct storeArgHandler

struct nullArgHandler
{
void operator() (String& key, String& value, const String& data, int equal_index, int pos, int key_end_pos, int next_index) { }
void operator() (String& key, String& value, const String& data, int equal_index, int pos, int key_end_pos, int next_index) {
(void)key; (void)value; (void)data; (void)equal_index; (void)pos; (void)key_end_pos; (void)next_index;
// do nothing
}
};

void ESP8266WebServer::_parseArguments(const String& data) {
Expand All @@ -288,17 +291,13 @@ void ESP8266WebServer::_parseArguments(const String& data) {

_currentArgCount = _parseArgumentsPrivate(data, nullArgHandler());

// allocate one more (even if counted==0)
// this is needed because {"plain": plainBuf} is always added
// allocate one more, this is needed because {"plain": plainBuf} is always added
_currentArgs = new RequestArgument[_currentArgCount + 1];

(void)_parseArgumentsPrivate(data, storeArgHandler());
}


int ESP8266WebServer::_parseArgumentsPrivate(const String& data, std::function<void(String&,String&,const String&,int,int,int,int)> handler) {
// counted<0: parse only, return counted arguments
// counted>=0: allocate counted+1, parse and store "counted" arguments

#ifdef DEBUG_ESP_HTTP_SERVER
DEBUG_OUTPUT.print("args: ");
Expand Down Expand Up @@ -329,9 +328,9 @@ int ESP8266WebServer::_parseArgumentsPrivate(const String& data, std::function<v

// handle key/value
if ((int)pos < key_end_pos) {
// do not store or count empty ending key ("url?x=y;")

handler(_currentArgs[arg_total].key, _currentArgs[arg_total].value, data, equal_index, pos, key_end_pos, next_index);
RequestArgument& arg = _currentArgs[arg_total];
handler(arg.key, arg.value, data, equal_index, pos, key_end_pos, next_index);

++arg_total;
pos = next_index + 1;
Expand Down Expand Up @@ -414,7 +413,7 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
DEBUG_OUTPUT.println(argFilename);
#endif
//use GET to set the filename if uploading using blob
if (argFilename == F("blob") && hasArg(FPSTR(filename)))
if (argFilename == F("blob") && hasArg(FPSTR(filename)))
argFilename = arg(FPSTR(filename));
}
#ifdef DEBUG_ESP_HTTP_SERVER
Expand Down Expand Up @@ -570,7 +569,7 @@ bool ESP8266WebServer::_parseForm(WiFiClient& client, String boundary, uint32_t
arg.value = postArgs[iarg].value;
}
_currentArgCount = iarg;
if (postArgs)
if (postArgs)
delete[] postArgs;
return true;
}
Expand Down
0