mirror of
https://github.com/penpot/penpot.git
synced 2026-07-11 16:48:59 +00:00
The plugin text API rejected negative letter-spacing even though the product UI allows -200..200 (typography.cljs). Two defects in frontend/src/app/plugins/text.cljs: - `letter-spacing-re` (`#"^\d*\.?\d*$"`) had no provision for a leading minus, so any negative value failed validation. - The text-range `:letterSpacing` setter inverted its guard: it used `(or (empty? value) (re-matches ...))` to mean "invalid", which rejected matching values and let non-numeric input through. The text-shape setter and the sibling `lineHeight` range setter both correctly use `(not (re-matches ...))`. Fix the regex to allow an optional leading minus and add the missing `not` so the range setter matches the shape setter. Adds regression coverage for the regex accept/reject contract. Fixes #9780 Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com> Signed-off-by: Filip Sajdak <filip.sajdak@siili.com>
38 lines
1.2 KiB
Clojure
38 lines
1.2 KiB
Clojure
;; This Source Code Form is subject to the terms of the Mozilla Public
|
|
;; License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
;; file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
;;
|
|
;; Copyright (c) KALEIDOS INC
|
|
|
|
(ns frontend-tests.plugins.text-test
|
|
(:require
|
|
[app.plugins.text :as plugins.text]
|
|
[cljs.test :as t :include-macros true]))
|
|
|
|
;; Regression coverage for issue #9780.
|
|
;;
|
|
;; `letterSpacing` accepts negative tracking in the product UI (-200..200,
|
|
;; see typography.cljs), but the plugin validator regex rejected any leading
|
|
;; minus, so negative values were refused. `letter-spacing-re` is the shared
|
|
;; predicate behind both the shape- and range-level setters; pin its
|
|
;; accept/reject contract here.
|
|
|
|
(def ^:private letter-spacing-re @#'plugins.text/letter-spacing-re)
|
|
|
|
(defn- valid? [s] (boolean (re-matches letter-spacing-re s)))
|
|
|
|
(t/deftest letter-spacing-re-accepts-negative-values
|
|
(t/is (valid? "-0.56"))
|
|
(t/is (valid? "-12"))
|
|
(t/is (valid? "-200")))
|
|
|
|
(t/deftest letter-spacing-re-accepts-non-negative-values
|
|
(t/is (valid? "0"))
|
|
(t/is (valid? "12"))
|
|
(t/is (valid? "1.5")))
|
|
|
|
(t/deftest letter-spacing-re-rejects-non-numeric
|
|
(t/is (not (valid? "abc")))
|
|
(t/is (not (valid? "1-2")))
|
|
(t/is (not (valid? "--1"))))
|