0
Fork 0
mirror of https://github.com/penpot/penpot.git synced 2025-02-23 07:16:07 -05:00

🐛 Fix issue where users can import tokens with invalid characters (#5623)

This commit is contained in:
Andrei Fëdorov 2025-01-20 17:13:58 +01:00 committed by GitHub
parent 1395629e5a
commit 69cb70a5ae
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 10 additions and 5 deletions

View file

@ -59,7 +59,8 @@
[t] [t]
(token-types 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? (defn valid-token-name-ref?
[n] [n]

View file

@ -46,14 +46,13 @@
Caution: This will allow a trailing dot like `token-name.`, Caution: This will allow a trailing dot like `token-name.`,
But we will trim that in the `finalize-name`, But we will trim that in the `finalize-name`,
to not throw too many errors while the user is editing." to not throw too many errors while the user is editing."
#"([a-zA-Z0-9-]+\.?)*") #"(?!\$)([a-zA-Z0-9-$]+\.?)*")
(def valid-token-name-schema (def valid-token-name-schema
(m/-simple-schema (m/-simple-schema
{:type :token/invalid-token-name {:type :token/invalid-token-name
:pred #(re-matches valid-token-name-regexp %) :pred #(re-matches valid-token-name-regexp %)
:type-properties {:error/fn #(str (:value %) " is not a valid token name. :type-properties {:error/fn #(str (:value %) (tr "workspace.token.token-name-validation-error"))}}))
Token names should only contain letters and digits separated by . characters.")}}))
(defn token-name-schema (defn token-name-schema
"Generate a dynamic schema validation to check if a token path derived from the name already exists at `tokens-tree`." "Generate a dynamic schema validation to check if a token path derived from the name already exists at `tokens-tree`."

View file

@ -6318,6 +6318,12 @@ msgstr "You currently have no themes."
msgid "workspace.token.num-sets" msgid "workspace.token.num-sets"
msgstr "%s 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 #: src/app/main/ui/workspace/tokens/sidebar.cljs:66
msgid "workspace.token.original-value" msgid "workspace.token.original-value"
msgstr "Original value: " msgstr "Original value: "
@ -6931,4 +6937,3 @@ msgstr "Notifications"
msgid "comments.mentions.not-found" msgid "comments.mentions.not-found"
msgstr "No people found for @%s" msgstr "No people found for @%s"