Scheduling infrastructure for absolutely everyone.
slugify lenient (#25923)
Anik Dhabal Babu593ed461c80d
diff --git a/apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/input-event-types.service.ts b/apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/input-event-types.service.tsindex 988ebee5b88..fe392fef169 100644--- a/apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/input-event-types.service.ts+++ b/apps/api/v2/src/ee/event-types/event-types_2024_06_14/services/input-event-types.service.ts@@ -27,7 +27,7 @@ import {import { UserWithProfile } from "@/modules/users/users.repository";import { Injectable, BadRequestException } from "@nestjs/common";-import { slugify } from "@calcom/platform-libraries";+import { slugifyLenient } from "@calcom/platform-libraries";import { getApps, getUsersCredentialsIncludeServiceAccountKey } from "@calcom/platform-libraries/app-store";import {validateCustomEventName,@@ -146,7 +146,7 @@ export class InputEventTypesService_2024_06_14 {? this.transformInputBookerActiveBookingsLimit(bookerActiveBookingsLimit): {};- const slugifiedSlug = slugify(slug);+ const slugifiedSlug = slugifyLenient(slug);const metadata: EventTypeMetadata = {bookerLayouts: this.transformInputBookerLayouts(bookerLayouts),@@ -249,7 +249,7 @@ export class InputEventTypesService_2024_06_14 {const eventType = {...rest,- ...(slug ? { slug: slugify(slug) } : {}),+ ...(slug ? { slug: slugifyLenient(slug) } : {}),length: lengthInMinutes,locations: locations ? this.transformInputLocations(locations) : undefined,bookingFields: effectiveBookingFieldsdiff --git a/apps/api/v2/src/modules/organizations/event-types/services/input.service.ts b/apps/api/v2/src/modules/organizations/event-types/services/input.service.tsindex e2bc83df181..0402d5cf624 100644--- a/apps/api/v2/src/modules/organizations/event-types/services/input.service.ts+++ b/apps/api/v2/src/modules/organizations/event-types/services/input.service.ts@@ -8,7 +8,7 @@ import { UsersRepository } from "@/modules/users/users.repository";import { BadRequestException, Injectable, NotFoundException } from "@nestjs/common";import { SchedulingType } from "@calcom/platform-libraries";-import { slugify } from "@calcom/platform-libraries";+import { slugifyLenient } from "@calcom/platform-libraries";import { EventTypeMetadata } from "@calcom/platform-libraries/event-types";import {CreateTeamEventTypeInput_2024_06_14,@@ -43,7 +43,7 @@ export class InputOrganizationsEventTypesService {teamId: number,inputEventType: CreateTeamEventTypeInput_2024_06_14) {- const slugifiedInputEventType = { ...inputEventType, slug: slugify(inputEventType.slug) };+ const slugifiedInputEventType = { ...inputEventType, slug: slugifyLenient(inputEventType.slug) };await this.validateInputLocations(teamId, inputEventType.locations);await this.validateHosts(teamId, inputEventType.hosts);@@ -79,7 +79,7 @@ export class InputOrganizationsEventTypesService {inputEventType: UpdateTeamEventTypeInput_2024_06_14) {const slugifiedInputEventType = inputEventType.slug- ? { ...inputEventType, slug: slugify(inputEventType.slug) }+ ? { ...inputEventType, slug: slugifyLenient(inputEventType.slug) }: inputEventType;await this.validateInputLocations(teamId, inputEventType.locations);diff --git a/packages/lib/slugify-lenient.ts b/packages/lib/slugify-lenient.tsnew file mode 100644index 00000000000..b792196b5dd--- /dev/null+++ b/packages/lib/slugify-lenient.ts@@ -0,0 +1,20 @@+/**+ * Only applies minimal transformations to prevent blocking issues:+ * - Removes leading dashes (could break URL parsing)+ * - Removes leading periods (could break URL parsing)+ * - Removes leading underscores (could break URL parsing)+ * - Trims whitespace+ */+export const slugifyLenient = (str: string): string => {+ if (!str) {+ return "";+ }++ return str+ .trim() // Remove whitespace from both sides+ .replace(/^-+/, "") // Remove dashes from start+ .replace(/^\.+/, "") // Remove periods from start+ .replace(/^_+/, ""); // Remove underscores from start+};++export default slugifyLenient;diff --git a/packages/platform/libraries/index.ts b/packages/platform/libraries/index.tsindex add140456e9..d4382874ba2 100644--- a/packages/platform/libraries/index.ts+++ b/packages/platform/libraries/index.ts@@ -20,6 +20,7 @@ import { paymentDataSelect } from "@calcom/prisma/selects/payment";import { createNewUsersConnectToOrgIfExists } from "@calcom/trpc/server/routers/viewer/teams/inviteMember/utils";export { slugify } from "@calcom/lib/slugify";+export { slugifyLenient } from "@calcom/lib/slugify-lenient";export { getBookingForReschedule };export type { EventBusyDate } from "@calcom/types/Calendar";