Forbid whitespaces in parameters (#3672)
This commit is contained in:
@@ -61,6 +61,7 @@ function WorkflowParameterAddPanel({ type, onClose, onSave }: Props) {
|
||||
const reservedKeys = ["current_item", "current_value", "current_index"];
|
||||
const isCloud = useContext(CloudContext);
|
||||
const [key, setKey] = useState("");
|
||||
const hasWhitespace = /\s/.test(key);
|
||||
const [urlParameterKey, setUrlParameterKey] = useState("");
|
||||
const [description, setDescription] = useState("");
|
||||
const [bitwardenCollectionId, setBitwardenCollectionId] = useState("");
|
||||
@@ -108,6 +109,11 @@ function WorkflowParameterAddPanel({ type, onClose, onSave }: Props) {
|
||||
<div className="space-y-1">
|
||||
<Label className="text-xs text-slate-300">Key</Label>
|
||||
<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 className="space-y-1">
|
||||
<Label className="text-xs text-slate-300">Description</Label>
|
||||
@@ -398,6 +404,14 @@ function WorkflowParameterAddPanel({ type, onClose, onSave }: Props) {
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (hasWhitespace) {
|
||||
toast({
|
||||
variant: "destructive",
|
||||
title: "Failed to add parameter",
|
||||
description: "Key cannot contain whitespaces",
|
||||
});
|
||||
return;
|
||||
}
|
||||
if (reservedKeys.includes(key)) {
|
||||
toast({
|
||||
variant: "destructive",
|
||||
|
||||
@@ -73,6 +73,7 @@ function WorkflowParameterEditPanel({
|
||||
}: Props) {
|
||||
const isCloud = useContext(CloudContext);
|
||||
const [key, setKey] = useState(initialValues.key);
|
||||
const hasWhitespace = /\s/.test(key);
|
||||
const isBitwardenCredential =
|
||||
initialValues.parameterType === "credential" &&
|
||||
parameterIsBitwardenCredential(initialValues);
|
||||
@@ -192,6 +193,11 @@ function WorkflowParameterEditPanel({
|
||||
<div className="space-y-1">
|
||||
<Label className="text-xs text-slate-300">Key</Label>
|
||||
<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 className="space-y-1">
|
||||
<Label className="text-xs text-slate-300">Description</Label>
|
||||
@@ -480,6 +486,15 @@ function WorkflowParameterEditPanel({
|
||||
});
|
||||
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 (
|
||||
parameterType === "json" &&
|
||||
|
||||
@@ -3,7 +3,7 @@ from dataclasses import dataclass
|
||||
from enum import StrEnum
|
||||
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.forge.sdk.workflow.models.parameter import OutputParameter, ParameterType, WorkflowParameterType
|
||||
@@ -74,6 +74,13 @@ class ParameterYAML(BaseModel, abc.ABC):
|
||||
key: str
|
||||
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):
|
||||
# There is a mypy bug with Literal. Without the type: ignore, mypy will raise an error:
|
||||
|
||||
Reference in New Issue
Block a user