From ccc734055f05597a685f320cb60779d4c8e2ada4 Mon Sep 17 00:00:00 2001 From: Alonso Torres Date: Thu, 4 Jun 2026 11:38:46 +0200 Subject: [PATCH] :bug: Fix problem with stroke-cap migration (#10019) --- common/src/app/common/files/migrations.cljc | 36 +++++++++++++------ .../common_tests/files_migrations_test.cljc | 20 +++++++---- 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/common/src/app/common/files/migrations.cljc b/common/src/app/common/files/migrations.cljc index aafd4cbbfd..147df1d1cc 100644 --- a/common/src/app/common/files/migrations.cljc +++ b/common/src/app/common/files/migrations.cljc @@ -1839,18 +1839,32 @@ ;; This will fix incorrectly created strokes from SVG imports ;; that have the stroke-cap at the shape level instead of at the stroke level -(defmethod migrate-data "0024-fix-stroke-cap-placement" +(defmethod migrate-data "0024b-fix-stroke-cap-placement" [data _] - (letfn [(fix-shape [shape] - (let [cap-start (get shape :stroke-cap-start) - cap-end (get shape :stroke-cap-end)] - (if (or (some? cap-start) (some? cap-end)) - (cond-> (dissoc shape :stroke-cap-start :stroke-cap-end) - (and (some? cap-start) (seq (:strokes shape))) - (assoc-in [:strokes 0 :stroke-cap-start] cap-start) + (letfn [(check-strokes [strokes] + (->> strokes + (mapv (fn [stroke] + (cond-> stroke + (string? (:stroke-cap-start stroke)) + (update :stroke-cap-start keyword) + (string? (:stroke-cap-end stroke)) + (update :stroke-cap-end keyword)))))) - (and (some? cap-end) (seq (:strokes shape))) - (assoc-in [:strokes 0 :stroke-cap-end] cap-end)) + (fix-shape [shape] + (let [cap-start (keyword (get shape :stroke-cap-start)) + cap-end (keyword (get shape :stroke-cap-end))] + (if (or (some? cap-start) (some? cap-end)) + (-> shape + (dissoc :stroke-cap-start :stroke-cap-end) + + (cond-> (seq (:strokes shape)) + (update :strokes check-strokes) + + (and (some? cap-start) (seq (:strokes shape))) + (assoc-in [:strokes 0 :stroke-cap-start] cap-start) + + (and (some? cap-end) (seq (:strokes shape))) + (assoc-in [:strokes 0 :stroke-cap-end] cap-end))) shape))) (update-container [container] @@ -1941,4 +1955,4 @@ "0021-fix-shape-svg-attrs" "0022-normalize-component-root-and-resync" "0023-repair-token-themes-with-inexistent-sets" - "0024-fix-stroke-cap-placement"])) + "0024b-fix-stroke-cap-placement"])) diff --git a/common/test/common_tests/files_migrations_test.cljc b/common/test/common_tests/files_migrations_test.cljc index 63dffe3e3c..3f6bd635fa 100644 --- a/common/test/common_tests/files_migrations_test.cljc +++ b/common/test/common_tests/files_migrations_test.cljc @@ -28,7 +28,7 @@ (t/is (= cfm/available-migrations (:migrations file'))) (t/is (= 3 (:sum (:data file')))))))) -(t/deftest migration-0024-fix-stroke-cap-placement +(t/deftest migration-0024b-fix-stroke-cap-placement (let [shape-id (uuid/next) page-id (uuid/next) data {:pages-index @@ -36,19 +36,27 @@ {:objects {shape-id {:id shape-id :type :path - :stroke-cap-start :round - :stroke-cap-end :round + :stroke-cap-start "round" + :stroke-cap-end "round" :strokes [{:stroke-color "#000000" + :stroke-opacity 1 + :stroke-style :svg + :stroke-width 2} + {:stroke-color "#000000" + :stroke-cap-start "round" + :stroke-cap-end "round" :stroke-opacity 1 :stroke-style :svg :stroke-width 2}]}}}}} - data' (cfm/migrate-data data "0024-fix-stroke-cap-placement")] + data' (cfm/migrate-data data "0024b-fix-stroke-cap-placement")] (let [shape (get-in data' [:pages-index page-id :objects shape-id])] (t/is (nil? (:stroke-cap-start shape)) "top-level cap removed") (t/is (nil? (:stroke-cap-end shape)) "top-level cap removed") (t/is (= :round (get-in shape [:strokes 0 :stroke-cap-start])) "cap moved into stroke") - (t/is (= :round (get-in shape [:strokes 0 :stroke-cap-end])) "cap moved into stroke")))) + (t/is (= :round (get-in shape [:strokes 0 :stroke-cap-end])) "cap moved into stroke") + (t/is (= :round (get-in shape [:strokes 1 :stroke-cap-start])) "correct cap type") + (t/is (= :round (get-in shape [:strokes 1 :stroke-cap-end])) "correct cap type")))) (t/deftest migration-0024-fix-stroke-cap-no-strokes (let [shape-id (uuid/next) @@ -61,7 +69,7 @@ :stroke-cap-start :round :stroke-cap-end :round :strokes []}}}}} - data' (cfm/migrate-data data "0024-fix-stroke-cap-placement")] + data' (cfm/migrate-data data "0024b-fix-stroke-cap-placement")] (let [shape (get-in data' [:pages-index page-id :objects shape-id])] (t/is (nil? (:stroke-cap-start shape)) "top-level cap removed even with no strokes")