MM-56881 Validate and ensure valid CustomStatus is stored (#26287)

* don't allow invalid CustomStatus

* allow empty emoji in custom status

* lint fix

* add english translation

* update for review comments.

* fix bad fix

---------

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Scott Bishel
2024-03-04 15:53:55 -07:00
коммит произвёл GitHub
родитель 5740b43922
Коммит 30454f241d
7 изменённых файлов: 78 добавлений и 8 удалений

Просмотреть файл

@@ -40,6 +40,15 @@ describe('getCustomStatus', () => {
expect(getCustomStatus(store.getState(), user.id)).toBeUndefined();
});
it('should return undefined when user with invalid json for custom status set', async () => {
const store = await configureStore();
const newUser = {...user};
newUser.props.customStatus = 'not a JSON string';
(UserSelectors.getUser as jest.Mock).mockReturnValue(user);
expect(getCustomStatus(store.getState(), user.id)).toBeUndefined();
});
it('should return customStatus object when there is custom status set', async () => {
const store = await configureStore();
const newUser = {...user};

Просмотреть файл

@@ -26,7 +26,15 @@ export function makeGetCustomStatus(): (state: GlobalState, userID?: string) =>
(state: GlobalState, userID?: string) => (userID ? getUser(state, userID) : getCurrentUser(state)),
(user) => {
const userProps = user?.props || {};
return userProps.customStatus ? JSON.parse(userProps.customStatus) : undefined;
let customStatus;
if (userProps.customStatus) {
try {
customStatus = JSON.parse(userProps.customStatus);
} catch (error) {
// do nothing if invalid, return undefined custom status.
}
}
return customStatus;
},
);
}