Add custom context name checker (regex) 86/142286/1
authorMu-Woong Lee <muwoong.lee@samsung.com>
Thu, 3 Aug 2017 08:41:38 +0000 (17:41 +0900)
committerMu-Woong Lee <muwoong.lee@samsung.com>
Thu, 3 Aug 2017 08:41:38 +0000 (17:41 +0900)
Change-Id: I8a47b8b038a22b203bc9c1654b258e4fc37ab100
Signed-off-by: Mu-Woong Lee <muwoong.lee@samsung.com>
src/trigger/CustomTemplate.cpp

index 68b88b1..780a86e 100644 (file)
@@ -14,6 +14,7 @@
  * limitations under the License.
  */
 
+#include <regex>
 #include "CustomTemplate.h"
 
 static std::list<CustomTemplate> __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);