Skip to content

Commit

Permalink
fix: add safe lower case util
Browse files Browse the repository at this point in the history
  • Loading branch information
xyhp915 authored and tiensonqin committed Oct 20, 2021
1 parent c23cfad commit 0cf5f87
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/main/frontend/components/sidebar.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@
(let [original-name (db-model/get-page-original-name name)]
[:a {:on-click (fn [e]
(util/stop e)
(let [name (string/lower-case name)]
(let [name (util/safe-lower-case name)]
(if (gobj/get e "shiftKey")
(when-let [page-entity (db/entity [:block/name name])]
(state/sidebar-add-block!
Expand Down Expand Up @@ -148,7 +148,7 @@
[:ul.favorites
(for [name favorites]
(when-not (string/blank? name)
(when (db/entity [:block/name (string/lower-case name)])
(when (db/entity [:block/name (util/safe-lower-case name)])
(favorite-item t name))))]))))

(rum/defc recent-pages
Expand All @@ -167,7 +167,7 @@
(filter string?))]
[:ul
(for [name pages]
(when (db/entity [:block/name (string/lower-case name)])
(when (db/entity [:block/name (util/safe-lower-case name)])
[:li {:key name}
(page-name name)]))])))

Expand Down Expand Up @@ -295,7 +295,7 @@
(let [page (:page default-home)
page (when (and (string? page)
(not (string/blank? page)))
(db/entity [:block/name (string/lower-case page)]))]
(db/entity [:block/name (util/safe-lower-case page)]))]
(if page
default-home
(dissoc default-home :page)))))
Expand All @@ -313,7 +313,7 @@
(when-let [pages (->> (seq sidebar)
(remove string/blank?))]
(doseq [page pages]
(let [page (string/lower-case page)
(let [page (util/safe-lower-case page)
[db-id block-type] (if (= page "contents")
["contents" :contents]
[page :page])]
Expand Down
5 changes: 5 additions & 0 deletions src/main/frontend/util.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,11 @@
(subs s (+ first-index (count pattern)) (count s))]
[s ""]))

(defn safe-lower-case
[s]
(if (string? s)
(string/lower-case s) s))

(defn split-first [pattern s]
(when-let [first-index (string/index-of s pattern)]
[(subs s 0 first-index)
Expand Down

0 comments on commit 0cf5f87

Please sign in to comment.