Appwidget id validation 69/78169/4
authorPiotr Ganicz <p.ganicz@samsung.com>
Mon, 4 Jul 2016 11:03:38 +0000 (13:03 +0200)
committerTomasz Iwanek <t.iwanek@samsung.com>
Mon, 4 Jul 2016 13:39:02 +0000 (06:39 -0700)
This patch provides the validation consistent with the documentation.

Change-Id: I9b6e330d578334d4b99ed3cb6d43a4d16de085d3

src/wgt_manifest_handlers/appwidget_handler.cc
src/wgt_manifest_handlers/appwidget_handler.h

index 889690ffa6e893d123824a6d669c337e0eb283e0..63e327faf9b09d7924c18a78b885597c0e226414 100644 (file)
@@ -79,8 +79,9 @@ const char kErrMsgInvalidContentDropViewSrc[] =
 const char kErrMsgContentDropViewHeightOutOfDomain[] =
     "Value of a height attribute in box-content element out of domain."
     " The value: ";
-
-const std::regex kStringRegex("[.][0-9a-zA-Z]+");
+const char kErrMsgIdIsNotValid[] = "ID of the app-widget should match"
+    " the pattern: ";
+const std::string kStringRegex("[.][0-9a-zA-Z]+");
 
 // If the error parameter is specified, it is filled with the given message
 // otherwise it does nothing.
@@ -544,12 +545,21 @@ bool AppWidgetHandler::Parse(
 
 bool AppWidgetHandler::Validate(
     const parser::ManifestData& data,
-    const parser::ManifestDataMap& /*handlers_output*/,
+    const parser::ManifestDataMap& handlers_output,
     std::string* error) const {
   const AppWidgetInfo& app_widget_info =
       static_cast<const AppWidgetInfo&>(data);
   const AppWidgetVector& app_widgets = app_widget_info.app_widgets();
 
+  auto tizen_app_info =
+      std::static_pointer_cast<TizenApplicationInfo>(
+              handlers_output.at(
+                  application_widget_keys::kTizenApplicationKey));
+
+  const std::string id_pattern =
+      tizen_app_info->id() + kStringRegex;
+  std::regex id_regex(id_pattern);
+
   for (const AppWidget& app_widget : app_widgets) {
     if (!app_widget.update_period.empty() &&
         app_widget.update_period.front() < 1800) {
@@ -557,6 +567,10 @@ bool AppWidgetHandler::Validate(
                std::to_string(app_widget.update_period.front()), error);
       return false;
     }
+    if (!std::regex_match(app_widget.id, id_regex)) {
+        SetError(kErrMsgIdIsNotValid, id_pattern, error);
+        return false;
+    }
 
     if (app_widget.label.default_value.empty() &&
         app_widget.label.lang_value_map.empty()) {
@@ -578,6 +592,10 @@ bool AppWidgetHandler::Validate(
   return true;
 }
 
+std::vector<std::string> AppWidgetHandler::PrerequisiteKeys() const {
+    return { application_widget_keys::kTizenApplicationKey };
+}
+
 std::string AppWidgetHandler::Key() const {
   return kTizenAppWidgetFullKey;
 }
index 23c72f5290d363b086c137bd9e76e9d615da802d..1b85010666d796fea48d718c63e4513484f9e7b8 100644 (file)
@@ -136,6 +136,7 @@ class AppWidgetHandler : public parser::ManifestHandler {
       const parser::ManifestDataMap& handlers_output,
       std::string* error) const override;
   std::string Key() const override;
+  std::vector<std::string> PrerequisiteKeys() const override;
 };
 
 }  // namespace parse