slugify lenient (#25923)

This commit is contained in:
Anik Dhabal Babu
2025-12-16 14:01:54 +00:00
committed by GitHub
parent b8827aca52
commit 593ed461c8
4 changed files with 27 additions and 6 deletions
@@ -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: effectiveBookingFields
@@ -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);
+20
View File
@@ -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;
+1
View File
@@ -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";