From 84391ccda146c860c1e719e3d85c78738169d5ef Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timoth=C3=A9e=20Poussard?= <tpoussard@neogeo.fr>
Date: Mon, 4 Oct 2021 12:33:41 +0200
Subject: [PATCH] check for irregular characters

---
 .../feature_type/FeatureTypeCustomForm.vue    | 19 +++++++++++++++++++
 src/views/feature_type/Feature_type_edit.vue  |  1 -
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/src/components/feature_type/FeatureTypeCustomForm.vue b/src/components/feature_type/FeatureTypeCustomForm.vue
index 140a62b0..83ac53b0 100644
--- a/src/components/feature_type/FeatureTypeCustomForm.vue
+++ b/src/components/feature_type/FeatureTypeCustomForm.vue
@@ -249,12 +249,14 @@ export default {
       }
       this.updateStore();
     },
+
     removeCustomForm() {
       this.$store.commit(
         "feature_type/REMOVE_CUSTOM_FORM",
         this.customForm.dataKey
       );
     },
+
     updateStore() {
       const data = {
         dataKey: this.customForm.dataKey,
@@ -266,10 +268,21 @@ export default {
       };
       this.$store.commit("feature_type/UPDATE_CUSTOM_FORM", data);
     },
+
     trimWhiteSpace(string) {
       // TODO : supprimer les espaces pour chaque option au début et à la fin QUE à la validation
       return string.replace(/\s*,\s*/gi, ",");
     },
+
+    hasRegularCharacters(input) {
+      for (let char of input) {
+        if (!/[a-zA-Z0-9-_]/.test(char)) {
+          return false;
+        }
+      }
+      return true;
+    },
+
     checkCustomForm() {
       if (this.form.label.value === null) {
         this.form.label.errors = ["Veuillez compléter ce champ."];
@@ -278,6 +291,12 @@ export default {
         this.form.name.errors = ["Veuillez compléter ce champ."];
         this.form.label.errors = [];
         return false;
+      } else if (!this.hasRegularCharacters(this.form.name.value)) {
+        this.form.name.errors = [
+          "Veuillez utiliser seulement les caratères autorisés.",
+        ];
+        this.form.label.errors = [];
+        return false;
       }
       this.form.label.errors = [];
       this.form.name.errors = [];
diff --git a/src/views/feature_type/Feature_type_edit.vue b/src/views/feature_type/Feature_type_edit.vue
index 9ba25f8a..69b931dd 100644
--- a/src/views/feature_type/Feature_type_edit.vue
+++ b/src/views/feature_type/Feature_type_edit.vue
@@ -154,7 +154,6 @@
           Créer et importer le(s) signalement(s) du geojson
         </button>
 
-        <!-- // TODO: Add check script for form & other scripts // -->
       </form>
     </div>
   </div>
-- 
GitLab