Skip to content

Commit 5417012

Browse files
authored
Revert "fix: sanitize username input to prevent hyperlinks (calcom#24210)" (calcom#24916)
This reverts commit 7d16da5.
1 parent 8e818e0 commit 5417012

3 files changed

Lines changed: 11 additions & 24 deletions

File tree

apps/web/components/ui/UsernameAvailability/PremiumTextfield.tsx

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import { fetchUsername } from "@calcom/lib/fetchUsername";
1313
import hasKeyInMetadata from "@calcom/lib/hasKeyInMetadata";
1414
import { useDebounce } from "@calcom/lib/hooks/useDebounce";
1515
import { useLocale } from "@calcom/lib/hooks/useLocale";
16-
import slugify from "@calcom/lib/slugify";
1716
import type { RouterOutputs } from "@calcom/trpc/react";
1817
import { trpc } from "@calcom/trpc/react";
1918
import type { AppRouter } from "@calcom/trpc/types/server/routers/_app";
@@ -82,7 +81,7 @@ const PremiumTextfield = (props: ICustomUsernameProps) => {
8281

8382
useEffect(() => {
8483
// Use the current username or if it's not set, use the one available from stripe
85-
setInputUsernameValue(slugify(currentUsername || stripeCustomer?.username || "", true));
84+
setInputUsernameValue(currentUsername || stripeCustomer?.username || "");
8685
}, [setInputUsernameValue, currentUsername, stripeCustomer?.username]);
8786

8887
useEffect(() => {
@@ -106,8 +105,7 @@ const PremiumTextfield = (props: ICustomUsernameProps) => {
106105
const updateUsername = trpc.viewer.me.updateProfile.useMutation({
107106
onSuccess: async () => {
108107
onSuccessMutation && (await onSuccessMutation());
109-
const sanitizedUsername = slugify(inputUsernameValue || "");
110-
await update({ username: sanitizedUsername });
108+
await update({ username: inputUsernameValue });
111109
setOpenDialogSaveUsername(false);
112110
},
113111
onError: (error) => {
@@ -173,12 +171,11 @@ const PremiumTextfield = (props: ICustomUsernameProps) => {
173171
};
174172

175173
const saveUsername = () => {
176-
const sanitizedUsername = slugify(inputUsernameValue || "");
177174
if (usernameChangeCondition !== UsernameChangeStatusEnum.UPGRADE) {
178175
updateUsername.mutate({
179-
username: sanitizedUsername,
176+
username: inputUsernameValue,
180177
});
181-
setCurrentUsername(sanitizedUsername);
178+
setCurrentUsername(inputUsernameValue);
182179
}
183180
};
184181

@@ -237,8 +234,7 @@ const PremiumTextfield = (props: ICustomUsernameProps) => {
237234
if (searchParams?.toString() !== _searchParams.toString()) {
238235
router.replace(`${pathname}?${_searchParams.toString()}`);
239236
}
240-
const sanitized = slugify(event.target.value, true);
241-
setInputUsernameValue(sanitized);
237+
setInputUsernameValue(event.target.value);
242238
}}
243239
data-testid="username-input"
244240
/>

apps/web/components/ui/UsernameAvailability/UsernameTextfield.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import { DialogContent, DialogFooter, DialogClose } from "@calcom/ui/components/
1616
import { TextField } from "@calcom/ui/components/form";
1717
import { Icon } from "@calcom/ui/components/icon";
1818
import { Tooltip } from "@calcom/ui/components/tooltip";
19-
import slugify from "@calcom/lib/slugify";
2019

2120
import type { TRPCClientErrorLike } from "@trpc/client";
2221

@@ -73,11 +72,10 @@ const UsernameTextfield = (props: ICustomUsernameProps & Partial<React.Component
7372

7473
const updateUsernameMutation = trpc.viewer.me.updateProfile.useMutation({
7574
onSuccess: async () => {
76-
const sanitizedUsername = slugify(inputUsernameValue || "");
7775
onSuccessMutation && (await onSuccessMutation());
7876
setOpenDialogSaveUsername(false);
79-
setCurrentUsername(sanitizedUsername);
80-
await update({ username: sanitizedUsername });
77+
setCurrentUsername(inputUsernameValue);
78+
await update({ username: inputUsernameValue });
8179
},
8280
onError: (error) => {
8381
onErrorMutation && onErrorMutation(error);
@@ -110,9 +108,8 @@ const UsernameTextfield = (props: ICustomUsernameProps & Partial<React.Component
110108
};
111109

112110
const updateUsername = async () => {
113-
const sanitizedUsername = slugify(inputUsernameValue || "");
114111
updateUsernameMutation.mutate({
115-
username: sanitizedUsername,
112+
username: inputUsernameValue,
116113
});
117114
};
118115

@@ -137,8 +134,7 @@ const UsernameTextfield = (props: ICustomUsernameProps & Partial<React.Component
137134
)}
138135
onChange={(event) => {
139136
event.preventDefault();
140-
const sanitized = slugify(event.target.value, true);
141-
setInputUsernameValue(sanitized);
137+
setInputUsernameValue(event.target.value);
142138
}}
143139
data-testid="username-input"
144140
{...rest}

apps/web/components/ui/UsernameAvailability/index.tsx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import { Controller, useForm } from "react-hook-form";
66

77
import { useOrgBranding } from "@calcom/features/ee/organizations/context/provider";
88
import { WEBSITE_URL, IS_SELF_HOSTED } from "@calcom/lib/constants";
9-
import slugify from "@calcom/lib/slugify";
109
import { trpc } from "@calcom/trpc/react";
1110
import type { AppRouter } from "@calcom/trpc/types/server/routers/_app";
1211

@@ -57,7 +56,7 @@ export const UsernameAvailabilityField = ({
5756
: { username: currentUsernameState || "", setQuery: setCurrentUsernameState };
5857
const formMethods = useForm({
5958
defaultValues: {
60-
username: slugify(currentUsername || user.username || ""),
59+
username: currentUsername,
6160
},
6261
});
6362

@@ -79,11 +78,7 @@ export const UsernameAvailabilityField = ({
7978
setCurrentUsername={setCurrentUsername}
8079
inputUsernameValue={value}
8180
usernameRef={ref}
82-
setInputUsernameValue={(val) => {
83-
const displayValue = slugify(val, true);
84-
formMethods.setValue("username", displayValue);
85-
onChange?.(displayValue);
86-
}}
81+
setInputUsernameValue={onChange}
8782
onSuccessMutation={onSuccessMutation}
8883
onErrorMutation={onErrorMutation}
8984
disabled={!!user.organization?.id}

0 commit comments

Comments
 (0)