@@ -270,26 +270,27 @@ bool ESP8266WebServer::_collectHeader(const char* headerName, const char* header
270
270
return false ;
271
271
}
272
272
273
- int ESP8266WebServer::_parseArguments (const String& data, bool store) {
274
- // when store is true, a recursive call
275
- // with store=false is recursively called first
276
- // to evaluate the number of arguments
277
- // should we use a vector instead?
273
+ void ESP8266WebServer::_parseArguments (const String& data) {
274
+ int counted = _parseArgumentsPrivate (data, 0 );
275
+ (void )_parseArgumentsPrivate (data, counted);
276
+ }
277
+
278
+ int ESP8266WebServer::_parseArgumentsPrivate (const String& data, int counted) {
279
+ // counted==0: parsing only, return counted arguments
280
+ // counted!=0: parsing and storing "counted" arguments
278
281
279
282
#ifdef DEBUG_ESP_HTTP_SERVER
280
283
DEBUG_OUTPUT.print (" args: " );
281
284
DEBUG_OUTPUT.println (data);
282
285
#endif
283
286
284
- if (store ) {
287
+ if (counted > 0 ) {
285
288
if (_currentArgs)
286
289
delete[] _currentArgs;
287
290
_currentArgs = 0 ;
288
- }
289
291
290
- if (store) {
291
- _currentArgCount = _parseArguments (data, false );
292
- _currentArgs = new RequestArgument[_currentArgCount+1 ];
292
+ // allocate one more, this is needed (search "plainBuf" in this file)
293
+ _currentArgs = new RequestArgument[(_currentArgCount = counted) + 1 ];
293
294
}
294
295
295
296
size_t pos = 0 ;
@@ -319,7 +320,7 @@ int ESP8266WebServer::_parseArguments(const String& data, bool store) {
319
320
if (keyEndPos >= (int )pos) {
320
321
// do not store or count empty ending key ("url?x=y;")
321
322
322
- if (store ) {
323
+ if (counted > 0 ) {
323
324
RequestArgument& arg = _currentArgs[arg_total];
324
325
arg.key = urlDecode (data.substring (pos, keyEndPos));
325
326
if ((equal_index != -1 ) && ((equal_index < next_index - 1 ) || (next_index == -1 )))
@@ -347,7 +348,7 @@ int ESP8266WebServer::_parseArguments(const String& data, bool store) {
347
348
DEBUG_OUTPUT.println (arg_total);
348
349
#endif
349
350
350
- if (store )
351
+ if (counted > 0 )
351
352
_currentArgCount = arg_total;
352
353
353
354
return arg_total;
0 commit comments