Parcourir la source

fix: invalid '+' for graph name not checked for import

Gabriel Horner il y a 2 ans
Parent
commit
7676aa1fc1

+ 1 - 1
src/main/frontend/components/imports.cljs

@@ -137,7 +137,7 @@
   (rum/local "" ::input)
   [state sqlite-input-e opts]
   (let [*input (::input state)
-        on-submit #(if (fs-util/include-reserved-chars? @*input)
+        on-submit #(if (repo/invalid-graph-name? @*input)
                      (repo/invalid-graph-name-warning)
                      (lsq-import-handler sqlite-input-e (assoc opts :graph-name @*input)))]
     [:div.container

+ 9 - 4
src/main/frontend/components/repo.cljs

@@ -128,8 +128,8 @@
                     (mobile-util/native-platform?))
             [:div.mr-8
              (ui/button
-               (t :open-a-directory)
-               :on-click #(state/pub-event! [:graph/setup-a-repo]))])]]
+              (t :open-a-directory)
+              :on-click #(state/pub-event! [:graph/setup-a-repo]))])]]
 
         (when (and (file-sync/enable-sync?) login?)
           [:div
@@ -283,14 +283,19 @@
      [:li "+ (plus)"]]]
    :warning false))
 
+(defn invalid-graph-name?
+  "Returns boolean indicating if DB graph name is invalid. Must be kept in sync with invalid-graph-name-warning"
+  [graph-name]
+  (or (fs-util/include-reserved-chars? graph-name)
+      (string/includes? graph-name "+")))
+
 (rum/defcs new-db-graph <
   (rum/local "" ::graph-name)
   [state]
   (let [*graph-name (::graph-name state)
         new-db-f (fn []
                    (when-not (string/blank? @*graph-name)
-                     (if (or (fs-util/include-reserved-chars? @*graph-name)
-                             (string/includes? @*graph-name "+"))
+                     (if (invalid-graph-name? @*graph-name)
                        (invalid-graph-name-warning)
                        (do
                          (repo-handler/new-db! @*graph-name)