diff --git a/keyserver/src/creators/account-creator.js b/keyserver/src/creators/account-creator.js --- a/keyserver/src/creators/account-creator.js +++ b/keyserver/src/creators/account-creator.js @@ -10,7 +10,7 @@ import { validUsernameRegex, oldValidUsernameRegex, -} from 'lib/shared/account-utils.js'; +} from 'lib/shared/account-validation-utils.js'; import { hasMinCodeVersion } from 'lib/shared/version-utils.js'; import type { RegisterResponse, diff --git a/keyserver/src/database/setup-db.js b/keyserver/src/database/setup-db.js --- a/keyserver/src/database/setup-db.js +++ b/keyserver/src/database/setup-db.js @@ -3,7 +3,7 @@ import ashoat from 'lib/facts/ashoat.js'; import bots from 'lib/facts/bots.js'; import genesis from 'lib/facts/genesis.js'; -import { usernameMaxLength } from 'lib/shared/account-utils.js'; +import { usernameMaxLength } from 'lib/shared/account-validation-utils.js'; import { sortIDs } from 'lib/shared/relationship-utils.js'; import { undirectedStatus } from 'lib/types/relationship-types.js'; import { threadTypes } from 'lib/types/thread-types.js'; diff --git a/keyserver/src/push/send.js b/keyserver/src/push/send.js --- a/keyserver/src/push/send.js +++ b/keyserver/src/push/send.js @@ -9,7 +9,7 @@ import _pickBy from 'lodash/fp/pickBy.js'; import uuidv4 from 'uuid/v4.js'; -import { oldValidUsernameRegex } from 'lib/shared/account-utils.js'; +import { oldValidUsernameRegex } from 'lib/shared/account-validation-utils.js'; import { isMentioned } from 'lib/shared/mention-utils.js'; import { createMessageInfo, diff --git a/landing/subscription-form.react.js b/landing/subscription-form.react.js --- a/landing/subscription-form.react.js +++ b/landing/subscription-form.react.js @@ -2,7 +2,7 @@ import * as React from 'react'; -import { validEmailRegex } from 'lib/shared/account-utils.js'; +import { validEmailRegex } from 'lib/shared/account-validation-utils.js'; import css from './subscription-form.css'; diff --git a/lib/shared/account-utils.js b/lib/shared/account-utils.js --- a/lib/shared/account-utils.js +++ b/lib/shared/account-utils.js @@ -9,27 +9,6 @@ import type { CurrentUserInfo } from '../types/user-types.js'; import { isValidEthereumAddress } from '../utils/siwe-utils.js'; -const usernameMaxLength = 191; -const usernameMinLength = 1; -const secondCharRange = `{${usernameMinLength - 1},${usernameMaxLength - 1}}`; -const validUsernameRegexString = `^[a-zA-Z0-9][a-zA-Z0-9-_]${secondCharRange}$`; -const validUsernameRegex: RegExp = new RegExp(validUsernameRegexString); - -// usernames used to be less restrictive (eg single chars were allowed) -// use oldValidUsername when dealing with existing accounts -const oldValidUsernameRegexString = '[a-zA-Z0-9-_]+'; -const oldValidUsernameRegex: RegExp = new RegExp( - `^${oldValidUsernameRegexString}$`, -); - -const validEmailRegex: RegExp = new RegExp( - /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+/.source + - /@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?/.source + - /(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.source, -); - -const validHexColorRegex: RegExp = /^[a-fA-F0-9]{6}$/; - function invalidSessionDowngrade( currentReduxState: AppState, actionCurrentUserInfo: ?CurrentUserInfo, @@ -103,14 +82,8 @@ } export { - usernameMaxLength, - oldValidUsernameRegexString, - validUsernameRegex, - oldValidUsernameRegex, - validEmailRegex, invalidSessionDowngrade, invalidSessionRecovery, - validHexColorRegex, accountHasPassword, userIdentifiedByETHAddress, getETHAddressForUserInfo, diff --git a/lib/shared/account-validation-utils.js b/lib/shared/account-validation-utils.js new file mode 100644 --- /dev/null +++ b/lib/shared/account-validation-utils.js @@ -0,0 +1,31 @@ +// @flow + +const usernameMaxLength = 191; +const usernameMinLength = 1; +const secondCharRange = `{${usernameMinLength - 1},${usernameMaxLength - 1}}`; +const validUsernameRegexString = `^[a-zA-Z0-9][a-zA-Z0-9-_]${secondCharRange}$`; +const validUsernameRegex: RegExp = new RegExp(validUsernameRegexString); + +// usernames used to be less restrictive (eg single chars were allowed) +// use oldValidUsername when dealing with existing accounts +const oldValidUsernameRegexString = '[a-zA-Z0-9-_]+'; +const oldValidUsernameRegex: RegExp = new RegExp( + `^${oldValidUsernameRegexString}$`, +); + +const validEmailRegex: RegExp = new RegExp( + /^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+/.source + + /@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?/.source + + /(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/.source, +); + +const validHexColorRegex: RegExp = /^[a-fA-F0-9]{6}$/; + +export { + usernameMaxLength, + oldValidUsernameRegexString, + validUsernameRegex, + oldValidUsernameRegex, + validEmailRegex, + validHexColorRegex, +}; diff --git a/lib/shared/mention-utils.js b/lib/shared/mention-utils.js --- a/lib/shared/mention-utils.js +++ b/lib/shared/mention-utils.js @@ -1,6 +1,6 @@ // @flow -import { oldValidUsernameRegexString } from './account-utils.js'; +import { oldValidUsernameRegexString } from './account-validation-utils.js'; import SearchIndex from './search-index.js'; import { threadOtherMembers } from './thread-utils.js'; import { stringForUserExplicit } from './user-utils.js'; diff --git a/lib/shared/messages/change-settings-message-spec.js b/lib/shared/messages/change-settings-message-spec.js --- a/lib/shared/messages/change-settings-message-spec.js +++ b/lib/shared/messages/change-settings-message-spec.js @@ -24,7 +24,7 @@ import type { ThreadInfo } from '../../types/thread-types.js'; import type { RelativeUserInfo } from '../../types/user-types.js'; import { ET, type EntityText } from '../../utils/entity-text.js'; -import { validHexColorRegex } from '../account-utils.js'; +import { validHexColorRegex } from '../account-validation-utils.js'; import { notifRobotextForMessageInfo } from '../notif-utils.js'; import { threadLabel } from '../thread-utils.js'; diff --git a/lib/utils/avatar-utils.js b/lib/utils/avatar-utils.js --- a/lib/utils/avatar-utils.js +++ b/lib/utils/avatar-utils.js @@ -4,7 +4,7 @@ import type { TUnion, TInterface } from 'tcomb'; import { tRegex, tShape, tString } from './validation-utils.js'; -import { validHexColorRegex } from '../shared/account-utils.js'; +import { validHexColorRegex } from '../shared/account-validation-utils.js'; import { onlyOneEmojiRegex } from '../shared/emojis.js'; import type { ENSAvatarDBContent, diff --git a/lib/utils/validation-utils.js b/lib/utils/validation-utils.js --- a/lib/utils/validation-utils.js +++ b/lib/utils/validation-utils.js @@ -16,7 +16,7 @@ validEmailRegex, oldValidUsernameRegex, validHexColorRegex, -} from '../shared/account-utils.js'; +} from '../shared/account-validation-utils.js'; import type { PlatformDetails } from '../types/device-types'; import type { MediaMessageServerDBContent, diff --git a/native/account/log-in-panel.react.js b/native/account/log-in-panel.react.js --- a/native/account/log-in-panel.react.js +++ b/native/account/log-in-panel.react.js @@ -10,7 +10,7 @@ import { validEmailRegex, oldValidUsernameRegex, -} from 'lib/shared/account-utils.js'; +} from 'lib/shared/account-validation-utils.js'; import { type LogInInfo, type LogInExtraInfo, diff --git a/native/account/register-panel.react.js b/native/account/register-panel.react.js --- a/native/account/register-panel.react.js +++ b/native/account/register-panel.react.js @@ -15,7 +15,7 @@ import { registerActionTypes, register } from 'lib/actions/user-actions.js'; import { createLoadingStatusSelector } from 'lib/selectors/loading-selectors.js'; -import { validUsernameRegex } from 'lib/shared/account-utils.js'; +import { validUsernameRegex } from 'lib/shared/account-validation-utils.js'; import type { RegisterInfo, LogInExtraInfo, diff --git a/native/utils/typeahead-utils.js b/native/utils/typeahead-utils.js --- a/native/utils/typeahead-utils.js +++ b/native/utils/typeahead-utils.js @@ -1,6 +1,6 @@ // @flow -import { oldValidUsernameRegexString } from 'lib/shared/account-utils.js'; +import { oldValidUsernameRegexString } from 'lib/shared/account-validation-utils.js'; // Native regex is a little bit different than web one as // there are no named capturing groups yet on native. diff --git a/web/account/traditional-login-form.react.js b/web/account/traditional-login-form.react.js --- a/web/account/traditional-login-form.react.js +++ b/web/account/traditional-login-form.react.js @@ -9,7 +9,7 @@ import { oldValidUsernameRegex, validEmailRegex, -} from 'lib/shared/account-utils.js'; +} from 'lib/shared/account-validation-utils.js'; import type { LogInExtraInfo, LogInStartingPayload, diff --git a/web/utils/typeahead-utils.js b/web/utils/typeahead-utils.js --- a/web/utils/typeahead-utils.js +++ b/web/utils/typeahead-utils.js @@ -3,7 +3,7 @@ import classNames from 'classnames'; import * as React from 'react'; -import { oldValidUsernameRegexString } from 'lib/shared/account-utils.js'; +import { oldValidUsernameRegexString } from 'lib/shared/account-validation-utils.js'; import { getNewTextAndSelection } from 'lib/shared/mention-utils.js'; import { stringForUserExplicit } from 'lib/shared/user-utils.js'; import type { SetState } from 'lib/types/hook-types.js';