Trim profile names when setting them

This commit is contained in:
Josh Perez 2022-01-26 16:58:00 -05:00 committed by GitHub
parent 5f34ece87c
commit 0fa069f260
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 70 additions and 5 deletions

View file

@ -1,4 +1,4 @@
// Copyright 2021 Signal Messenger, LLC
// Copyright 2021-2022 Signal Messenger, LLC
// SPDX-License-Identifier: AGPL-3.0-only
import React, { useCallback, useEffect, useRef, useState } from 'react';
@ -37,6 +37,7 @@ import {
import { Spinner } from './Spinner';
import { UsernameSaveState } from '../state/ducks/conversationsEnums';
import { MAX_USERNAME, MIN_USERNAME } from '../types/Username';
import { isWhitespace, trim } from '../util/whitespaceStringUtil';
export enum EditState {
None = 'None',
@ -286,7 +287,16 @@ export const ProfileEditor = ({
(avatar: Uint8Array | undefined) => {
setAvatarBuffer(avatar);
setEditState(EditState.None);
onProfileChanged(stagedProfile, avatar);
onProfileChanged(
{
...stagedProfile,
firstName: trim(stagedProfile.firstName),
familyName: stagedProfile.familyName
? trim(stagedProfile.familyName)
: undefined,
},
avatar
);
},
[onProfileChanged, stagedProfile]
);
@ -422,7 +432,8 @@ export const ProfileEditor = ({
const shouldDisableSave =
!stagedProfile.firstName ||
(stagedProfile.firstName === fullName.firstName &&
stagedProfile.familyName === fullName.familyName);
stagedProfile.familyName === fullName.familyName) ||
isWhitespace(stagedProfile.firstName);
content = (
<>