mirror of
https://github.com/penpot/penpot.git
synced 2026-08-06 21:08:34 +00:00
🐛 Fix error when creating a token with an invalid name (#8216)
This commit is contained in:
parent
852b31c3a0
commit
9569fa2bcb
@ -40,6 +40,7 @@
|
|||||||
- Fix app freeze when introducing an error on a very long token name [Taiga #13214](https://tree.taiga.io/project/penpot/issue/13214)
|
- Fix app freeze when introducing an error on a very long token name [Taiga #13214](https://tree.taiga.io/project/penpot/issue/13214)
|
||||||
- Fix import a file with shadow tokens [Taiga #13229](https://tree.taiga.io/project/penpot/issue/13229)
|
- Fix import a file with shadow tokens [Taiga #13229](https://tree.taiga.io/project/penpot/issue/13229)
|
||||||
- Fix allow spaces on token description [Taiga #13184](https://tree.taiga.io/project/penpot/issue/13184)
|
- Fix allow spaces on token description [Taiga #13184](https://tree.taiga.io/project/penpot/issue/13184)
|
||||||
|
- Fix error when creating a token with an invalid name [Taiga #13219](https://tree.taiga.io/project/penpot/issue/13219)
|
||||||
|
|
||||||
## 2.12.1
|
## 2.12.1
|
||||||
|
|
||||||
|
|||||||
@ -97,9 +97,12 @@
|
|||||||
(def token-types
|
(def token-types
|
||||||
(into #{} (keys token-type->dtcg-token-type)))
|
(into #{} (keys token-type->dtcg-token-type)))
|
||||||
|
|
||||||
|
(def token-name-validation-regex
|
||||||
|
#"^[a-zA-Z0-9_-][a-zA-Z0-9$_-]*(\.[a-zA-Z0-9$_-]+)*$")
|
||||||
|
|
||||||
(def token-name-ref
|
(def token-name-ref
|
||||||
[:re {:title "TokenNameRef" :gen/gen sg/text}
|
[:re {:title "TokenNameRef" :gen/gen sg/text}
|
||||||
#"^[a-zA-Z0-9_-][a-zA-Z0-9$_-]*(\.[a-zA-Z0-9$_-]+)*$"])
|
token-name-validation-regex])
|
||||||
|
|
||||||
(def ^:private schema:color
|
(def ^:private schema:color
|
||||||
[:map
|
[:map
|
||||||
|
|||||||
@ -11,6 +11,7 @@
|
|||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.data.macros :as dm]
|
[app.common.data.macros :as dm]
|
||||||
[app.common.types.color :as cl]
|
[app.common.types.color :as cl]
|
||||||
|
[app.common.types.token :as cto]
|
||||||
[app.common.types.tokens-lib :as ctob]
|
[app.common.types.tokens-lib :as ctob]
|
||||||
[app.main.data.style-dictionary :as sd]
|
[app.main.data.style-dictionary :as sd]
|
||||||
[app.main.data.tinycolor :as tinycolor]
|
[app.main.data.tinycolor :as tinycolor]
|
||||||
@ -51,12 +52,15 @@
|
|||||||
;; Both variants provide identical color-picker and text-input behavior, but
|
;; Both variants provide identical color-picker and text-input behavior, but
|
||||||
;; differ in how they persist the value within the form’s nested structure.
|
;; differ in how they persist the value within the form’s nested structure.
|
||||||
|
|
||||||
|
|
||||||
(defn- resolve-value
|
(defn- resolve-value
|
||||||
[tokens prev-token token-name value]
|
[tokens prev-token token-name value]
|
||||||
(let [token
|
(let [valid-token-name?
|
||||||
|
(and (string? token-name)
|
||||||
|
(re-matches cto/token-name-validation-regex token-name))
|
||||||
|
|
||||||
|
token
|
||||||
{:value value
|
{:value value
|
||||||
:name (if (str/blank? token-name)
|
:name (if (or (not valid-token-name?) (str/blank? token-name))
|
||||||
"__PENPOT__TOKEN__NAME__PLACEHOLDER__"
|
"__PENPOT__TOKEN__NAME__PLACEHOLDER__"
|
||||||
token-name)}
|
token-name)}
|
||||||
|
|
||||||
|
|||||||
@ -50,9 +50,13 @@
|
|||||||
|
|
||||||
(defn- resolve-value
|
(defn- resolve-value
|
||||||
[tokens prev-token token-name value]
|
[tokens prev-token token-name value]
|
||||||
(let [token
|
(let [valid-token-name?
|
||||||
|
(and (string? token-name)
|
||||||
|
(re-matches cto/token-name-validation-regex token-name))
|
||||||
|
|
||||||
|
token
|
||||||
{:value (cto/split-font-family value)
|
{:value (cto/split-font-family value)
|
||||||
:name (if (str/blank? token-name)
|
:name (if (or (not valid-token-name?) (str/blank? token-name))
|
||||||
"__PENPOT__TOKEN__NAME__PLACEHOLDER__"
|
"__PENPOT__TOKEN__NAME__PLACEHOLDER__"
|
||||||
token-name)}
|
token-name)}
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
(:require
|
(:require
|
||||||
[app.common.data :as d]
|
[app.common.data :as d]
|
||||||
[app.common.files.tokens :as cft]
|
[app.common.files.tokens :as cft]
|
||||||
|
[app.common.types.token :as cto]
|
||||||
[app.common.types.tokens-lib :as ctob]
|
[app.common.types.tokens-lib :as ctob]
|
||||||
[app.main.data.style-dictionary :as sd]
|
[app.main.data.style-dictionary :as sd]
|
||||||
[app.main.data.workspace.tokens.format :as dwtf]
|
[app.main.data.workspace.tokens.format :as dwtf]
|
||||||
@ -140,9 +141,13 @@
|
|||||||
|
|
||||||
(defn- resolve-value
|
(defn- resolve-value
|
||||||
[tokens prev-token token-name value]
|
[tokens prev-token token-name value]
|
||||||
(let [token
|
(let [valid-token-name?
|
||||||
|
(and (string? token-name)
|
||||||
|
(re-matches cto/token-name-validation-regex token-name))
|
||||||
|
|
||||||
|
token
|
||||||
{:value value
|
{:value value
|
||||||
:name (if (str/blank? token-name)
|
:name (if (or (not valid-token-name?) (str/blank? token-name))
|
||||||
"__PENPOT__TOKEN__NAME__PLACEHOLDER__"
|
"__PENPOT__TOKEN__NAME__PLACEHOLDER__"
|
||||||
token-name)}
|
token-name)}
|
||||||
tokens
|
tokens
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user