Skip to content

Commit

Permalink
Reject invisible display names
Browse files Browse the repository at this point in the history
  • Loading branch information
clbn committed Feb 8, 2022
1 parent a605f05 commit 149269d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/redux/reducers/page-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import _ from 'lodash';

import * as ActionTypes from '../action-types';
import * as ActionHelpers from '../action-helpers';
import { getSummaryPeriod } from '../../utils';
import { getSummaryPeriod, userParser } from '../../utils';

const { request, response } = ActionHelpers;

Expand All @@ -12,7 +12,7 @@ const initialState = {

export default function pageView(state = initialState, action) {
const getPageByOffset = (offset) => (offset ? Math.floor(offset / 30 + 1) : 1);
const getUserOnResponse = () => _.find(action.payload.users, { username: action.request.username });
const getUserOnResponse = () => userParser(_.find(action.payload.users, { username: action.request.username }));
const getFormattedName = (user) => user.screenName + (user.username !== user.screenName ? ' (' + user.username + ')' : '');

switch (action.type) {
Expand Down
9 changes: 7 additions & 2 deletions src/utils/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,14 @@ export function getFullDate(timestamp) {
export function userParser(user) {
const newUser = { ...user };

// Remove invisible characters from display name
if (newUser.screenName) {
newUser.screenName = newUser.screenName.replace(/[\u180E\u2000-\u200F\u2060\u2800\u3000\u3164\u{1D159}]/gu, '');
}

// Missing display name
if (!user.screenName) {
newUser.screenName = user.username;
if (!newUser.screenName) {
newUser.screenName = newUser.username;
}

return newUser;
Expand Down

0 comments on commit 149269d

Please sign in to comment.