From: Mu-Woong Lee Date: Thu, 3 Aug 2017 08:41:38 +0000 (+0900) Subject: Add custom context name checker (regex) X-Git-Tag: submit/tizen/20170926.083539^2~13 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=ff9ddf48cecac1a3f8823487504df860072d70e8;p=platform%2Fcore%2Fapi%2Fcontext.git Add custom context name checker (regex) Change-Id: I8a47b8b038a22b203bc9c1654b258e4fc37ab100 Signed-off-by: Mu-Woong Lee --- diff --git a/src/trigger/CustomTemplate.cpp b/src/trigger/CustomTemplate.cpp index 68b88b1..780a86e 100644 --- a/src/trigger/CustomTemplate.cpp +++ b/src/trigger/CustomTemplate.cpp @@ -14,6 +14,7 @@ * limitations under the License. */ +#include #include "CustomTemplate.h" static std::list __instances; @@ -39,7 +40,8 @@ bool CustomTemplate::add(const std::string& name, const std::string& attrTmpl) { IF_FAIL_RETURN(!get(name), false); - //TODO: validity check of the name (regex) + static std::regex nameRegex(R"~(^[\w-\._\/]+$)~", std::regex::optimize); + IF_FAIL_RETURN_TAG(std::regex_match(name, nameRegex), false, _E, "Invalid name"); Json::Reader reader; Json::Value tmplJson; @@ -52,6 +54,7 @@ bool CustomTemplate::add(const std::string& name, const std::string& attrTmpl) } //TODO: further validity check of the template + // Does it contain all necessary fields, ...? __instances.emplace_back(name, tmplJson);