From 5808c873f6743fd53892e5d18a93417bb4dabfd1 Mon Sep 17 00:00:00 2001 From: "alonso.torres" Date: Thu, 19 Nov 2026 09:57:53 +0100 Subject: [PATCH] :bug: Reject imported components v1 files that have graphics A library in the components v1 format with graphics and no components imported, but its graphics were lost: only the removed v1 to v2 migration turned them into components, and v2 has no graphics section, so the file showed no assets at all. `check-components-v2` now rejects a components v1 file with graphics (`:media`) as it rejects one with components, with `:file-in-components-v1`. Found by the components Qase run (PENPOT-1598). Test: `check-components-v2-looks-at-components-and-component-shapes` (binfile-test). AI-assisted-by: claude-opus-5-5 --- backend/src/app/binfile/common.clj | 12 ++++++++---- backend/test/backend_tests/binfile_test.clj | 6 ++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/backend/src/app/binfile/common.clj b/backend/src/app/binfile/common.clj index f9af5727c1..6e994b00b5 100644 --- a/backend/src/app/binfile/common.clj +++ b/backend/src/app/binfile/common.clj @@ -454,17 +454,21 @@ (true? (:main-instance shape)))) (defn- has-component-data? - [{:keys [components pages-index]}] + "Whether a components v1 file holds library data that only the removed + v1 to v2 migration could convert: components, shapes linked to them, or + graphics (`:media`), which v2 turns into components." + [{:keys [components media pages-index]}] (or (seq components) + (seq media) (some (fn [page] (some component-shape? (vals (:objects page)))) (vals pages-index)))) (defn check-components-v2 "Check that an imported file can be stored as a components v2 file. A file without the `components/v2` feature is in the deprecated - components v1 format: it is rejected when it has components or shapes - linked to them, and otherwise takes the feature as it is. Returns the - file." + components v1 format: it is rejected when it has components, shapes + linked to them or graphics, and otherwise takes the feature as it is. + Returns the file." [{:keys [features data] :as file}] (cond (contains? features "components/v2") diff --git a/backend/test/backend_tests/binfile_test.clj b/backend/test/backend_tests/binfile_test.clj index 1f04a7ddb1..ac057c7e24 100644 --- a/backend/test/backend_tests/binfile_test.clj +++ b/backend/test/backend_tests/binfile_test.clj @@ -3813,6 +3813,12 @@ (t/is (rejected? (file #{} {:shape-ref (uuid/custom 2 2)} nil))) (t/is (rejected? (file #{} {:main-instance true} nil)))) + (t/testing "a file without components/v2 is rejected when it has graphics" + (let [media-id (uuid/custom 6 1)] + (t/is (rejected? (assoc-in (file #{} {} nil) [:data :media] + {media-id {:id media-id :name "icon" :width 24 :height 24 + :mtype "image/svg+xml" :media-id (uuid/custom 6 2)}}))))) + (t/testing "a file without components/v2 and without component data takes the feature" (t/is (= #{"components/v2"} (:features (bfc/check-components-v2 (file #{} {} nil))))))