Skip to content

Commit 49efe87

Browse files
committed
more lenient path args access
1 parent 37debb1 commit 49efe87

File tree

4 files changed

+7
-9
lines changed

4 files changed

+7
-9
lines changed

libraries/ESP8266WebServer/README.rst

+4-4
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ Getting information about request arguments
110110

111111
.. code:: cpp
112112
113-
const String & arg();
114-
const String & argName();
113+
const String & arg(int);
114+
const String & argName(int);
115115
int args();
116-
bool hasArg();
116+
bool hasArg(const String&);
117117
118118
``arg`` - get request argument value, use ``arg("plain")`` to get POST body
119119

@@ -170,7 +170,7 @@ Getting information about request path arguments
170170

171171
.. code:: cpp
172172
173-
const String & pathArg(unsigned int) const;
173+
const String & pathArg(int) const;
174174
int pathArgs() const;
175175
176176
``pathArg`` - get request path argument by index (starting with 0)

libraries/ESP8266WebServer/src/ESP8266WebServer-impl.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -664,8 +664,8 @@ int ESP8266WebServerTemplate<ServerType>::pathArgs() const {
664664
}
665665

666666
template <typename ServerType>
667-
const String& ESP8266WebServerTemplate<ServerType>::pathArg(unsigned int i) const {
668-
if (_currentHandler != nullptr)
667+
const String& ESP8266WebServerTemplate<ServerType>::pathArg(int i) const {
668+
if (i >= 0 && _currentHandler != nullptr && i < _currentHandler->pathArgsSize())
669669
return _currentHandler->pathArg(i);
670670
return emptyString;
671671
}

libraries/ESP8266WebServer/src/ESP8266WebServer.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class ESP8266WebServerTemplate
141141
// Allows setting server options (i.e. SSL keys) by the instantiator
142142
ServerType &getServer() { return _server; }
143143

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

147147
const String& arg(const String& name) const; // get request argument value by name

libraries/ESP8266WebServer/src/detail/RequestHandler.h

-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
#include <ESP8266WebServer.h>
55
#include <vector>
6-
#include <assert.h>
76

87
namespace esp8266webserver {
98

@@ -79,7 +78,6 @@ class RequestHandler {
7978
}
8079

8180
const String& pathArg(unsigned int i) const {
82-
assert(i < pathArgs.size());
8381
return pathArgs[i];
8482
}
8583
};

0 commit comments

Comments
 (0)