Browse Source

fix: safe-parse-float/int received nil parameter

This can results in data-loss in dev environment due to malli
validation has been enabled.
Tienson Qin 3 years ago
parent
commit
afc9e7a9f4

+ 4 - 2
src/main/frontend/extensions/pdf/highlights.cljs

@@ -49,7 +49,8 @@
            (when-not active-hl
              (.on (.-eventBus viewer) (name :restore-last-page)
                   (fn [last-page]
-                    (set! (.-currentPageNumber viewer) (util/safe-parse-int last-page)))))))))
+                    (when last-page
+                      (set! (.-currentPageNumber viewer) (util/safe-parse-int last-page))))))))))
    [viewer])
   nil)
 
@@ -793,7 +794,8 @@
        (p/catch
         (p/let [data (pdf-assets/load-hls-data$ pdf-current)
                 {:keys [highlights extra]} data]
-          (set-initial-page! (or (util/safe-parse-int (:page extra)) 1))
+          (set-initial-page! (or (when-let [page (:page extra)]
+                                   (util/safe-parse-int page)) 1))
           (set-hls-state! {:initial-hls highlights :latest-hls highlights :extra extra :loaded true}))
 
         ;; error

+ 9 - 3
src/main/frontend/extensions/srs.cljs

@@ -315,9 +315,15 @@
          (satisfies? ICard card)]}
   (let [block (.-block card)
         props (get-block-card-properties block)
-        last-interval (or (util/safe-parse-float (get props card-last-interval-property)) 0)
-        repeats (or (util/safe-parse-int (get props card-repeats-property)) 0)
-        last-ef (or (util/safe-parse-float (get props card-last-easiness-factor-property)) 2.5)
+        last-interval (or
+                       (when-let [v (get props card-last-interval-property)]
+                         (util/safe-parse-float v))
+                       0)
+        repeats (or (when-let [v (get props card-repeats-property)]
+                      (util/safe-parse-int v))
+                    0)
+        last-ef (or (when-let [v (get props card-last-easiness-factor-property)]
+                      (util/safe-parse-float v)) 2.5)
         [next-interval next-repeats next-ef of-matrix*]
         (next-interval last-interval repeats last-ef score @of-matrix)
         next-interval* (if (< next-interval 0) 0 next-interval)