From b9ca4e7f9b49ec27a2e94114e318e77a1eab6826 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Tue, 13 Apr 2021 12:14:40 +0200 Subject: [PATCH] :bug: Fixes issue when parsing exponential numbers in paths --- CHANGES.md | 1 + frontend/src/app/util/geom/path.cljs | 21 +++++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 63cd75150..8ca74a0f1 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -10,6 +10,7 @@ ### :bug: Bugs fixed - Fixes problem with pan and space [#811](https://github.com/penpot/penpot/issues/811) +- Fixes issue when parsing exponential numbers in paths ### :arrow_up: Deps updates diff --git a/frontend/src/app/util/geom/path.cljs b/frontend/src/app/util/geom/path.cljs index 0defe2053..454b2da20 100644 --- a/frontend/src/app/util/geom/path.cljs +++ b/frontend/src/app/util/geom/path.cljs @@ -28,11 +28,11 @@ (into [] (impl-simplify/simplify points tolerance true))))) ;; -(def commands-regex #"(?i)[a-z][^a-z]*") +(def commands-regex #"(?i)[mzlhvcsqta][^mzlhvcsqta]*") ;; Matches numbers for path values allows values like... -.01, 10, +12.22 ;; 0 and 1 are special because can refer to flags -(def num-regex #"[+-]?(\d+(\.\d+)?|\.\d+)") +(def num-regex #"[+-]?(\d+(\.\d+)?|\.\d+)(e[+-]?\d+)?") (def flag-regex #"[01]") @@ -370,14 +370,15 @@ (reduce simplify-command [[start] start-pos start-pos start-pos start-pos]) (first)))) -(defn path->content [string] - (let [clean-string (-> string - (str/trim) - ;; Change "commas" for spaces - (str/replace #"," " ") - ;; Remove all consecutive spaces - (str/replace #"\s+" " ")) - commands (re-seq commands-regex clean-string)] +(defn path->content [path-str] + (let [clean-path-str + (-> path-str + (str/trim) + ;; Change "commas" for spaces + (str/replace #"," " ") + ;; Remove all consecutive spaces + (str/replace #"\s+" " ")) + commands (re-seq commands-regex clean-path-str)] (-> (mapcat parse-command commands) (simplify-commands))))