mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-07-27 10:24:48 +10:00
fix: enhance resume schema validation and improve slugify function for CJK input
This commit is contained in:
@@ -6,12 +6,12 @@ import { jsonPatchOperationSchema } from "@reactive-resume/utils/resume/patch";
|
|||||||
|
|
||||||
const resumeSchema = createSelectSchema(schema.resume, {
|
const resumeSchema = createSelectSchema(schema.resume, {
|
||||||
id: z.string().describe("The ID of the resume."),
|
id: z.string().describe("The ID of the resume."),
|
||||||
name: z.string().min(1).describe("The name of the resume."),
|
name: z.string().trim().min(1).describe("The name of the resume."),
|
||||||
slug: z.string().min(1).describe("The slug of the resume."),
|
slug: z.string().trim().min(1).describe("The slug of the resume."),
|
||||||
tags: z.array(z.string()).describe("The tags of the resume."),
|
tags: z.array(z.string()).describe("The tags of the resume."),
|
||||||
isPublic: z.boolean().describe("Whether the resume is public."),
|
isPublic: z.boolean().describe("Whether the resume is public."),
|
||||||
isLocked: z.boolean().describe("Whether the resume is locked."),
|
isLocked: z.boolean().describe("Whether the resume is locked."),
|
||||||
password: z.string().min(6).nullable().describe("The password of the resume, if any."),
|
password: z.string().trim().min(6).max(64).nullable().describe("The password of the resume, if any."),
|
||||||
data: resumeDataSchema,
|
data: resumeDataSchema,
|
||||||
userId: z.string().describe("The ID of the user who owns the resume."),
|
userId: z.string().describe("The ID of the user who owns the resume."),
|
||||||
createdAt: z.date().describe("The date and time the resume was created."),
|
createdAt: z.date().describe("The date and time the resume was created."),
|
||||||
|
|||||||
@@ -50,6 +50,10 @@ describe("slugify", () => {
|
|||||||
it("handles unicode emojis by stripping them", () => {
|
it("handles unicode emojis by stripping them", () => {
|
||||||
expect(slugify("Hello 🌍 World")).toBe("hello-world");
|
expect(slugify("Hello 🌍 World")).toBe("hello-world");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("falls back to a non-empty slug for CJK input", () => {
|
||||||
|
expect(slugify("中文简历")).not.toBe("");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("getInitials", () => {
|
describe("getInitials", () => {
|
||||||
|
|||||||
@@ -16,7 +16,9 @@ export function generateId() {
|
|||||||
* @returns The slugified value.
|
* @returns The slugified value.
|
||||||
*/
|
*/
|
||||||
export function slugify(value: string) {
|
export function slugify(value: string) {
|
||||||
return _slugify(value, { decamelize: false });
|
const slug = _slugify(value, { decamelize: false });
|
||||||
|
if (slug || !value.trim()) return slug;
|
||||||
|
return slugify(generateRandomName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user