Skip to content

Commit

Permalink
fix: trim spaces in strings for names (#2527)
Browse files Browse the repository at this point in the history
* trim names in dashboard

* [autofix.ci] apply automated fixes

* missed changes

* [autofix.ci] apply automated fixes

* Changed method for trim

* [autofix.ci] apply automated fixes

* missed min max

---------

Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
  • Loading branch information
MichaelUnkey and autofix-ci[bot] authored Oct 28, 2024
1 parent f680c3d commit 8fb9d4d
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const formSchema = z.object({
keyId: z.string(),
name: z
.string()
.trim()
.transform((e) => (e === "" ? undefined : e))
.optional(),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const formSchema = z.object({
keyId: z.string(),
ownerId: z
.string()
.trim()
.transform((e) => (e === "" ? undefined : e))
.optional(),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,11 @@ const formSchema = z.object({
.default(16),
prefix: z
.string()
.trim()
.max(8, { message: "Please limit the prefix to under 8 characters." })
.optional(),
ownerId: z.string().optional(),
name: z.string().optional(),
ownerId: z.string().trim().optional(),
name: z.string().trim().optional(),
metaEnabled: z.boolean().default(false),
meta: z
.string()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { z } from "zod";
import { tags } from "@/lib/cache";
import { revalidateTag } from "../../../../actions";
const formSchema = z.object({
name: z.string(),
name: z.string().trim().min(3, "Name is required and should be at least 3 characters"),
apiId: z.string(),
workspaceId: z.string(),
});
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/app/(app)/apis/create-api-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { useForm } from "react-hook-form";
import { z } from "zod";

const formSchema = z.object({
name: z.string().min(2).max(50),
name: z.string().trim().min(3, "Name must be at least 3 characters long").max(50),
});

export const CreateApiButton = ({ ...rest }: React.ButtonHTMLAttributes<HTMLButtonElement>) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,13 @@ type Props = {
};

const formSchema = z.object({
name: z.string(),
name: z
.string()
.min(3)
.regex(/^[a-zA-Z0-9_:\-\.\*]+$/, {
message:
"Must be at least 3 characters long and only contain alphanumeric, colons, periods, dashes and underscores",
}),
description: z.string().optional(),
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ import { useForm } from "react-hook-form";
import { z } from "zod";

const formSchema = z.object({
identifier: z.string().min(2).max(250),
identifier: z
.string()
.trim()
.min(3, "Name is required and should be at least 3 characters")
.max(250),
limit: z.coerce.number().int().min(1).max(10_000),
duration: z.coerce
.number()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ import { useRouter } from "next/navigation";
import { useForm } from "react-hook-form";
import { z } from "zod";
const formSchema = z.object({
name: z.string(),
name: z
.string()
.trim()
.min(3)
.max(50)
.regex(/^[a-zA-Z0-9_\-\.]+$/, {
message:
"Name must be 3-50 characters long and can only contain letters, numbers, underscores, hyphens, and periods.",
}),
namespaceId: z.string(),
workspaceId: z.string(),
});
Expand Down Expand Up @@ -56,7 +64,7 @@ export const UpdateNamespaceName: React.FC<Props> = ({ namespace }) => {
});
async function onSubmit(values: z.infer<typeof formSchema>) {
if (values.name === namespace.name || !values.name) {
return toast.error("Please provide a valid name before saving.");
return toast.error("Please provide a different name before saving.");
}
await updateName.mutateAsync(values);
}
Expand Down
10 changes: 9 additions & 1 deletion apps/dashboard/app/(app)/ratelimits/create-namespace-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,15 @@ import { useForm } from "react-hook-form";
import { z } from "zod";

const formSchema = z.object({
name: z.string().regex(/^[a-zA-Z0-9_\-\.]{3,50}$/),
name: z
.string()
.trim()
.min(1, "Name must not be empty")
.max(50, "Name must not exceed 50 characters")
.regex(
/^[a-zA-Z0-9_\-\.]+$/,
"Only alphanumeric characters, underscores, hyphens, and periods are allowed",
),
});

export const CreateNamespaceButton = ({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const validCharactersRegex = /^[a-zA-Z0-9-_]+$/;

const formSchema = z.object({
workspaceId: z.string(),
name: z.string().min(3).regex(validCharactersRegex, {
name: z.string().trim().min(3).regex(validCharactersRegex, {
message: "Workspace can only contain letters, numbers, dashes, and underscores",
}),
});
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/app/new/create-api.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import { useRouter } from "next/navigation";
import { useForm } from "react-hook-form";
import { z } from "zod";
const formSchema = z.object({
name: z.string().min(3, "Name is required and should be at least 3 characters").max(50),
name: z.string().trim().min(3, "Name is required and should be at least 3 characters").max(50),
});

type Props = {
Expand Down
2 changes: 1 addition & 1 deletion apps/dashboard/app/new/create-workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { useForm } from "react-hook-form";
import { z } from "zod";

const formSchema = z.object({
name: z.string().min(3, "Name is required and should be at least 3 characters").max(50),
name: z.string().trim().min(3, "Name is required and should be at least 3 characters").max(50),
});

export const CreateWorkspace: React.FC = () => {
Expand Down

0 comments on commit 8fb9d4d

Please sign in to comment.