Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ const getCodeName = (name: string): string => {
return (
name
.trim()
// Filter out all characters that is not a letter, number or space
.replace(/[^a-zA-Z0-9\s]/g, '')
// Filter out all characters that is not a letter, number or space or underscore
.replace(/[^a-zA-Z0-9\s_]/g, '')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooops good catch

.replace(/\s/g, '_')
.toLowerCase()
)
Expand Down Expand Up @@ -181,7 +181,11 @@ export const NewVariableModal = (): JSX.Element => {
}
>
<div className="gap-4 flex flex-col">
<LemonField.Pure label="Name" className="gap-1">
<LemonField.Pure
label="Name"
className="gap-1"
info="Variable name must be alphanumeric and can only contain spaces and underscores"
>
<LemonInput
placeholder="Name"
value={variable.name}
Expand Down
4 changes: 2 additions & 2 deletions posthog/api/insight_variable.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ def create(self, validated_data):
validated_data["team_id"] = self.context["team_id"]
validated_data["created_by"] = self.context["request"].user

# Strips non alphanumeric values from name (other than spaces)
# Strips non alphanumeric values from name (other than spaces and underscores)
validated_data["code_name"] = (
"".join(n for n in validated_data["name"] if n.isalnum() or n == " ").replace(" ", "_").lower()
"".join(n for n in validated_data["name"] if n.isalnum() or n == " " or n == "_").replace(" ", "_").lower()
)

count = InsightVariable.objects.filter(
Expand Down
Loading