Forbid whitespaces in parameters (#3672)

This commit is contained in:
pedrohsdb
2025-10-09 15:02:48 -07:00
committed by GitHub
parent 619191d37f
commit 1c26b3b784
3 changed files with 37 additions and 1 deletions

View File

@@ -61,6 +61,7 @@ function WorkflowParameterAddPanel({ type, onClose, onSave }: Props) {
const reservedKeys = ["current_item", "current_value", "current_index"]; const reservedKeys = ["current_item", "current_value", "current_index"];
const isCloud = useContext(CloudContext); const isCloud = useContext(CloudContext);
const [key, setKey] = useState(""); const [key, setKey] = useState("");
const hasWhitespace = /\s/.test(key);
const [urlParameterKey, setUrlParameterKey] = useState(""); const [urlParameterKey, setUrlParameterKey] = useState("");
const [description, setDescription] = useState(""); const [description, setDescription] = useState("");
const [bitwardenCollectionId, setBitwardenCollectionId] = useState(""); const [bitwardenCollectionId, setBitwardenCollectionId] = useState("");
@@ -108,6 +109,11 @@ function WorkflowParameterAddPanel({ type, onClose, onSave }: Props) {
<div className="space-y-1"> <div className="space-y-1">
<Label className="text-xs text-slate-300">Key</Label> <Label className="text-xs text-slate-300">Key</Label>
<Input value={key} onChange={(e) => setKey(e.target.value)} /> <Input value={key} onChange={(e) => setKey(e.target.value)} />
{hasWhitespace && (
<p className="text-xs text-destructive">
Spaces are not allowed, consider using _
</p>
)}
</div> </div>
<div className="space-y-1"> <div className="space-y-1">
<Label className="text-xs text-slate-300">Description</Label> <Label className="text-xs text-slate-300">Description</Label>
@@ -398,6 +404,14 @@ function WorkflowParameterAddPanel({ type, onClose, onSave }: Props) {
}); });
return; return;
} }
if (hasWhitespace) {
toast({
variant: "destructive",
title: "Failed to add parameter",
description: "Key cannot contain whitespaces",
});
return;
}
if (reservedKeys.includes(key)) { if (reservedKeys.includes(key)) {
toast({ toast({
variant: "destructive", variant: "destructive",

View File

@@ -73,6 +73,7 @@ function WorkflowParameterEditPanel({
}: Props) { }: Props) {
const isCloud = useContext(CloudContext); const isCloud = useContext(CloudContext);
const [key, setKey] = useState(initialValues.key); const [key, setKey] = useState(initialValues.key);
const hasWhitespace = /\s/.test(key);
const isBitwardenCredential = const isBitwardenCredential =
initialValues.parameterType === "credential" && initialValues.parameterType === "credential" &&
parameterIsBitwardenCredential(initialValues); parameterIsBitwardenCredential(initialValues);
@@ -192,6 +193,11 @@ function WorkflowParameterEditPanel({
<div className="space-y-1"> <div className="space-y-1">
<Label className="text-xs text-slate-300">Key</Label> <Label className="text-xs text-slate-300">Key</Label>
<Input value={key} onChange={(e) => setKey(e.target.value)} /> <Input value={key} onChange={(e) => setKey(e.target.value)} />
{hasWhitespace && (
<p className="text-xs text-destructive">
Spaces are not allowed, consider using _
</p>
)}
</div> </div>
<div className="space-y-1"> <div className="space-y-1">
<Label className="text-xs text-slate-300">Description</Label> <Label className="text-xs text-slate-300">Description</Label>
@@ -480,6 +486,15 @@ function WorkflowParameterEditPanel({
}); });
return; return;
} }
if (hasWhitespace) {
toast({
variant: "destructive",
title: "Failed to save parameter",
description:
"Key cannot contain whitespace characters. Consider using underscores (_) instead.",
});
return;
}
if (type === "workflow") { if (type === "workflow") {
if ( if (
parameterType === "json" && parameterType === "json" &&

View File

@@ -3,7 +3,7 @@ from dataclasses import dataclass
from enum import StrEnum from enum import StrEnum
from typing import Annotated, Any, Literal from typing import Annotated, Any, Literal
from pydantic import BaseModel, Field from pydantic import BaseModel, Field, field_validator
from skyvern.config import settings from skyvern.config import settings
from skyvern.forge.sdk.workflow.models.parameter import OutputParameter, ParameterType, WorkflowParameterType from skyvern.forge.sdk.workflow.models.parameter import OutputParameter, ParameterType, WorkflowParameterType
@@ -74,6 +74,13 @@ class ParameterYAML(BaseModel, abc.ABC):
key: str key: str
description: str | None = None description: str | None = None
@field_validator("key")
@classmethod
def validate_no_whitespace(cls, v: str) -> str:
if any(char in v for char in [" ", "\t", "\n", "\r"]):
raise ValueError("Key cannot contain whitespaces")
return v
class AWSSecretParameterYAML(ParameterYAML): class AWSSecretParameterYAML(ParameterYAML):
# There is a mypy bug with Literal. Without the type: ignore, mypy will raise an error: # There is a mypy bug with Literal. Without the type: ignore, mypy will raise an error: