Skip to content

Commit

Permalink
[IMPROVE] Added MaxNickNameLength and MaxBioLength constants (#25231)
Browse files Browse the repository at this point in the history
* Added MaxNickNameLength and MaxBioLength constants

added above mentioned constants to remove magic numbers in a simple manner

* code style fixes

Co-authored-by: gabriellsh <[email protected]>
  • Loading branch information
aakash-gitdev and gabriellsh authored Apr 19, 2022
1 parent e419108 commit 15f55fd
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions apps/meteor/app/lib/server/functions/saveUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ import { checkEmailAvailability, checkUsernameAvailability, setUserAvatar, setEm
import { Users } from '../../../models/server';
import { callbacks } from '../../../../lib/callbacks';

const MAX_BIO_LENGTH = 260;
const MAX_NICKNAME_LENGTH = 120;

let html = '';
let passwordChangedHtml = '';
Meteor.startup(() => {
Expand Down Expand Up @@ -228,7 +231,7 @@ export function validateUserEditing(userId, userData) {

const handleBio = (updateUser, bio) => {
if (bio && bio.trim()) {
if (typeof bio !== 'string' || bio.length > 260) {
if (typeof bio !== 'string' || bio.length > MAX_BIO_LENGTH) {
throw new Meteor.Error('error-invalid-field', 'bio', {
method: 'saveUserProfile',
});
Expand All @@ -243,7 +246,7 @@ const handleBio = (updateUser, bio) => {

const handleNickname = (updateUser, nickname) => {
if (nickname && nickname.trim()) {
if (typeof nickname !== 'string' || nickname.length > 120) {
if (typeof nickname !== 'string' || nickname.length > MAX_NICKNAME_LENGTH) {
throw new Meteor.Error('error-invalid-field', 'nickname', {
method: 'saveUserProfile',
});
Expand Down

0 comments on commit 15f55fd

Please sign in to comment.