Skip to content

Commit 4168a2d

Browse files
authored
fix: prevent creating css variable with invalid name (#4319)
Closes #4292 Here instead of validation error I just remove "create" option. It is consitent with just random invalid name not starting with `--`. https://github.com/user-attachments/assets/214b71b9-1b88-49de-8eb0-4e815c67486f
1 parent 8d7cf57 commit 4168a2d

File tree

1 file changed

+8
-3
lines changed
  • apps/builder/app/builder/features/style-panel/sections/advanced

1 file changed

+8
-3
lines changed

apps/builder/app/builder/features/style-panel/sections/advanced/advanced.tsx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { lexer } from "css-tree";
12
import { colord } from "colord";
23
import {
34
memo,
@@ -111,10 +112,14 @@ const matchOrSuggestToCreate = (
111112
if (isFeatureEnabled("cssVars") === false) {
112113
return matched;
113114
}
114-
if (search.trim().startsWith("--")) {
115+
const propertyName = search.trim();
116+
if (
117+
propertyName.startsWith("--") &&
118+
lexer.match("<custom-ident>", propertyName).matched
119+
) {
115120
matched.unshift({
116-
value: search.trim(),
117-
label: `Create "${search.trim()}"`,
121+
value: propertyName,
122+
label: `Create "${propertyName}"`,
118123
});
119124
}
120125
return matched;

0 commit comments

Comments
 (0)