Skip to content

Commit 0ba7f62

Browse files
authored
fix: don't check for disallowed words when dealing with existing user names (@fehmer) (monkeytypegame#7949)
1 parent b570bd1 commit 0ba7f62

5 files changed

Lines changed: 17 additions & 13 deletions

File tree

frontend/src/ts/commandline/lists/navigation.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { isAuthenticated } from "../../states/core";
33
import { toggleFullscreen } from "../../utils/misc";
44
import { Command, withValidation } from "../types";
55
import { remoteValidation } from "../../utils/remote-validation";
6-
import { UserNameSchema } from "@monkeytype/schemas/users";
6+
import { UserNameWithoutFilterSchema } from "@monkeytype/schemas/users";
77
import Ape from "../../ape";
88

99
const commands: Command[] = [
@@ -60,7 +60,7 @@ const commands: Command[] = [
6060
icon: "fa-search",
6161
input: true,
6262
validation: {
63-
schema: UserNameSchema,
63+
schema: UserNameWithoutFilterSchema,
6464
debounceDelay: 1000,
6565
isValid: remoteValidation(
6666
async (name) => Ape.users.getProfile({ params: { uidOrName: name } }),

frontend/src/ts/components/pages/profile/ProfileSearchPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { UserNameSchema } from "@monkeytype/schemas/users";
1+
import { UserNameWithoutFilterSchema } from "@monkeytype/schemas/users";
22
import { createForm } from "@tanstack/solid-form";
33
import { createEffect, createSignal, JSXElement, Show } from "solid-js";
44

@@ -70,7 +70,7 @@ export function ProfileSearchPage(): JSXElement {
7070
<form.Field
7171
name="username"
7272
validators={{
73-
onChange: fromSchema(UserNameSchema),
73+
onChange: fromSchema(UserNameWithoutFilterSchema),
7474
onChangeAsyncDebounceMs: 1000,
7575
onChangeAsync: async (field) => {
7676
try {

frontend/src/ts/pages/friends.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import { getAuthenticatedUser } from "../firebase";
3131
import * as ServerConfiguration from "../ape/server-configuration";
3232
import { authEvent } from "../events/auth";
3333
import { Connection } from "@monkeytype/schemas/connections";
34-
import { Friend, UserNameSchema } from "@monkeytype/schemas/users";
34+
import { UserNameWithoutFilterSchema, Friend } from "@monkeytype/schemas/users";
3535

3636
import { showLoaderBar, hideLoaderBar } from "../states/loader-bar";
3737
import { LocalStorageWithSchema } from "../utils/local-storage-with-schema";
@@ -52,7 +52,7 @@ const addFriendModal = new SimpleModal({
5252
type: "text",
5353
initVal: "",
5454
validation: {
55-
schema: UserNameSchema,
55+
schema: UserNameWithoutFilterSchema,
5656
isValid: remoteValidation(
5757
async (name) => Ape.users.getNameAvailability({ params: { name } }),
5858
{ check: (data) => !data.available || "Unknown user" },

frontend/src/ts/utils/misc.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { lastElementFromArray } from "./arrays";
22
import { Config } from "@monkeytype/schemas/configs";
33
import { Mode, Mode2, PersonalBests } from "@monkeytype/schemas/shared";
44
import { Result } from "@monkeytype/schemas/results";
5-
import { RankAndCount, UserNameSchema } from "@monkeytype/schemas/users";
5+
import { RankAndCount } from "@monkeytype/schemas/users";
66
import { roundTo2 } from "@monkeytype/util/numbers";
77
import { animate, AnimationParams } from "animejs";
88
import { ElementWithUtils } from "./dom";
@@ -145,11 +145,6 @@ export function escapeHTML<T extends string | null | undefined>(str: T): T {
145145
return str.replace(/[&<>"'/`]/g, (char) => escapeMap[char] as string) as T;
146146
}
147147

148-
export function isUsernameValid(name: string): boolean {
149-
if (name === null || name === undefined || name === "") return false;
150-
return UserNameSchema.safeParse(name).success;
151-
}
152-
153148
export function clearTimeouts(timeouts: (number | NodeJS.Timeout)[]): void {
154149
timeouts.forEach((to) => {
155150
if (typeof to === "number") clearTimeout(to);

packages/schemas/src/users.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,9 +235,18 @@ export const FavoriteQuotesSchema = z.record(
235235
export type FavoriteQuotes = z.infer<typeof FavoriteQuotesSchema>;
236236

237237
export const UserEmailSchema = z.string().email();
238+
239+
/**
240+
* username schema without profanity check
241+
*/
242+
export const UserNameWithoutFilterSchema = slug().min(1).max(16);
243+
244+
/**
245+
* username schema with profanity check
246+
*/
238247
export const UserNameSchema = doesNotContainDisallowedWords(
239248
"substring",
240-
slug().min(1).max(16),
249+
UserNameWithoutFilterSchema,
241250
);
242251

243252
export const UserSchema = z.object({

0 commit comments

Comments
 (0)