mirror of
https://github.com/penpot/penpot.git
synced 2025-02-21 22:36:12 -05:00
🐛 Fix issue where users can import tokens with invalid characters (#5623)
This commit is contained in:
parent
1395629e5a
commit
69cb70a5ae
3 changed files with 10 additions and 5 deletions
|
@ -59,7 +59,8 @@
|
|||
[t]
|
||||
(token-types t))
|
||||
|
||||
(def token-name-ref :string)
|
||||
(def token-name-ref
|
||||
[:and :string [:re #"^(?!\$)([a-zA-Z0-9-$]+\.?)*(?<!\.)$"]])
|
||||
|
||||
(defn valid-token-name-ref?
|
||||
[n]
|
||||
|
|
|
@ -46,14 +46,13 @@
|
|||
Caution: This will allow a trailing dot like `token-name.`,
|
||||
But we will trim that in the `finalize-name`,
|
||||
to not throw too many errors while the user is editing."
|
||||
#"([a-zA-Z0-9-]+\.?)*")
|
||||
#"(?!\$)([a-zA-Z0-9-$]+\.?)*")
|
||||
|
||||
(def valid-token-name-schema
|
||||
(m/-simple-schema
|
||||
{:type :token/invalid-token-name
|
||||
:pred #(re-matches valid-token-name-regexp %)
|
||||
:type-properties {:error/fn #(str (:value %) " is not a valid token name.
|
||||
Token names should only contain letters and digits separated by . characters.")}}))
|
||||
:type-properties {:error/fn #(str (:value %) (tr "workspace.token.token-name-validation-error"))}}))
|
||||
|
||||
(defn token-name-schema
|
||||
"Generate a dynamic schema validation to check if a token path derived from the name already exists at `tokens-tree`."
|
||||
|
|
|
@ -6318,6 +6318,12 @@ msgstr "You currently have no themes."
|
|||
msgid "workspace.token.num-sets"
|
||||
msgstr "%s sets"
|
||||
|
||||
|
||||
#: src/app/main/ui/workspace/tokens/form.cljs:55
|
||||
msgid "workspace.token.token-name-validation-error"
|
||||
msgstr " is not a valid token name.
|
||||
Token names should only contain letters and digits separated by . characters and must not start with a $ sign."
|
||||
|
||||
#: src/app/main/ui/workspace/tokens/sidebar.cljs:66
|
||||
msgid "workspace.token.original-value"
|
||||
msgstr "Original value: "
|
||||
|
@ -6931,4 +6937,3 @@ msgstr "Notifications"
|
|||
|
||||
msgid "comments.mentions.not-found"
|
||||
msgstr "No people found for @%s"
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue