summaryrefslogtreecommitdiff
path: root/include/openbmc_dbus_rest.hpp
diff options
context:
space:
mode:
authorJosh Lehan <krellan@google.com>2022-03-30 03:10:44 +0300
committerEd Tanous <ed@tanous.net>2022-05-13 02:23:34 +0300
commit482c45a52e221882be5142a873cd828c380d7e54 (patch)
treea6451f283092a705f0cc201e6ed620a1807c5314 /include/openbmc_dbus_rest.hpp
parent1476687deb1697d865b20458a0097c9ab5fd44e2 (diff)
downloadbmcweb-482c45a52e221882be5142a873cd828c380d7e54.tar.xz
Separate validFilename into a separate function
This will generalize it and make it callable from other places Tested: Added test cases, they pass Signed-off-by: Josh Lehan <krellan@google.com> Change-Id: I8df30d6fe6753a2454d7051cc2d8813ddbf14bad
Diffstat (limited to 'include/openbmc_dbus_rest.hpp')
-rw-r--r--include/openbmc_dbus_rest.hpp10
1 files changed, 8 insertions, 2 deletions
diff --git a/include/openbmc_dbus_rest.hpp b/include/openbmc_dbus_rest.hpp
index 75e31f19f9..272776cd07 100644
--- a/include/openbmc_dbus_rest.hpp
+++ b/include/openbmc_dbus_rest.hpp
@@ -51,6 +51,13 @@ const constexpr char* forbiddenPropDesc =
const constexpr char* forbiddenResDesc =
"The specified resource cannot be created";
+inline bool validateFilename(const std::string& filename)
+{
+ std::regex validFilename(R"(^[\w\- ]+(\.?[\w\- ]*)$)");
+
+ return std::regex_match(filename, validFilename);
+}
+
inline void setErrorResponse(crow::Response& res,
boost::beast::http::status result,
const std::string& desc,
@@ -2538,8 +2545,7 @@ inline void requestRoutes(App& app)
[](const crow::Request&,
const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
const std::string& dumpId) {
- std::regex validFilename(R"(^[\w\- ]+(\.?[\w\- ]*)$)");
- if (!std::regex_match(dumpId, validFilename))
+ if (!validateFilename(dumpId))
{
asyncResp->res.result(
boost::beast::http::status::bad_request);