Skip to content

Commit

Permalink
more lenient path args access
Browse files Browse the repository at this point in the history
  • Loading branch information
mcspr committed Jul 25, 2024
1 parent 37debb1 commit 49efe87
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 9 deletions.
8 changes: 4 additions & 4 deletions libraries/ESP8266WebServer/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ Getting information about request arguments

.. code:: cpp
const String & arg();
const String & argName();
const String & arg(int);
const String & argName(int);
int args();
bool hasArg();
bool hasArg(const String&);
``arg`` - get request argument value, use ``arg("plain")`` to get POST body

Expand Down Expand Up @@ -170,7 +170,7 @@ Getting information about request path arguments

.. code:: cpp
const String & pathArg(unsigned int) const;
const String & pathArg(int) const;
int pathArgs() const;
``pathArg`` - get request path argument by index (starting with 0)
Expand Down
4 changes: 2 additions & 2 deletions libraries/ESP8266WebServer/src/ESP8266WebServer-impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -664,8 +664,8 @@ int ESP8266WebServerTemplate<ServerType>::pathArgs() const {
}

template <typename ServerType>
const String& ESP8266WebServerTemplate<ServerType>::pathArg(unsigned int i) const {
if (_currentHandler != nullptr)
const String& ESP8266WebServerTemplate<ServerType>::pathArg(int i) const {
if (i >= 0 && _currentHandler != nullptr && i < _currentHandler->pathArgsSize())
return _currentHandler->pathArg(i);
return emptyString;
}
Expand Down
2 changes: 1 addition & 1 deletion libraries/ESP8266WebServer/src/ESP8266WebServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ class ESP8266WebServerTemplate
// Allows setting server options (i.e. SSL keys) by the instantiator
ServerType &getServer() { return _server; }

const String& pathArg(unsigned int i) const; // get request path argument by number
const String& pathArg(int i) const; // get request path argument by number
int pathArgs() const; // get path arguments count

const String& arg(const String& name) const; // get request argument value by name
Expand Down
2 changes: 0 additions & 2 deletions libraries/ESP8266WebServer/src/detail/RequestHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#include <ESP8266WebServer.h>
#include <vector>
#include <assert.h>

namespace esp8266webserver {

Expand Down Expand Up @@ -79,7 +78,6 @@ class RequestHandler {
}

const String& pathArg(unsigned int i) const {
assert(i < pathArgs.size());
return pathArgs[i];
}
};
Expand Down

0 comments on commit 49efe87

Please sign in to comment.