Link: Fix incorrent parsing for invite links (#4342)

This commit is contained in:
Alexander Zinchuk 2024-03-08 12:48:42 +01:00
parent 00a98971b3
commit 550e2b4373
3 changed files with 10 additions and 11 deletions

View File

@ -7,7 +7,7 @@ import { getActions } from '../../global';
import { TME_LINK_PREFIX } from '../../config';
import { debounce } from '../../util/schedulers';
import {
isUsernameValid, MAX_USERNAME_LENGTH, MIN_USERNAME_LENGTH, USERNAME_REGEX,
isUsernameValid, MAX_USERNAME_LENGTH, MIN_UPDATE_USERNAME_LENGTH, USERNAME_REGEX,
} from '../../util/username';
import useLang from '../../hooks/useLang';
@ -53,7 +53,7 @@ const UsernameInput: FC<OwnProps> = ({
return [];
}
if (username.length < MIN_USERNAME_LENGTH) {
if (username.length < MIN_UPDATE_USERNAME_LENGTH) {
return [undefined, lang(`${langPrefix}InvalidShort`)];
}
if (username.length > MAX_USERNAME_LENGTH) {
@ -92,7 +92,7 @@ const UsernameInput: FC<OwnProps> = ({
setUsername(newUsername);
const isValid = newUsername === '' ? true : isUsernameValid(newUsername);
const isValid = newUsername === '' ? true : isUsernameValid(newUsername, true);
if (!isValid) return;
onChange?.(newUsername);

View File

@ -2,6 +2,7 @@ import type { ThreadId } from '../types';
import { RE_TG_LINK, RE_TME_LINK } from '../config';
import { ensureProtocol } from './ensureProtocol';
import { isUsernameValid } from './username';
export type DeepLinkMethod = 'resolve' | 'login' | 'passport' | 'settings' | 'join' | 'addstickers' | 'addemoji' |
'setlanguage' | 'addtheme' | 'confirmphone' | 'socks' | 'proxy' | 'privatepost' | 'bg' | 'share' | 'msg' | 'msg_url' |
@ -492,7 +493,3 @@ function getPathParams(url: URL) {
function getQueryParams(url: URL) {
return Object.fromEntries(url.searchParams);
}
function isUsernameValid(username: string) {
return /^\D([a-zA-Z0-9_]){1,64}$/.test(username);
}

View File

@ -1,9 +1,11 @@
export const MIN_USERNAME_LENGTH = 5;
export const MIN_USERNAME_LENGTH = 3; // Some bots have 3-letter usernames
export const MIN_UPDATE_USERNAME_LENGTH = 5; // 4 letter usernames are only available on Fragment
export const MAX_USERNAME_LENGTH = 32;
export const USERNAME_REGEX = /^\D([a-zA-Z0-9_]+)$/;
export const USERNAME_REGEX = /^[a-zA-Z]\w+$/;
export function isUsernameValid(username: string) {
return username.length >= MIN_USERNAME_LENGTH
export function isUsernameValid(username: string, isUpdating?: boolean) {
const minUsernameLength = isUpdating ? MIN_UPDATE_USERNAME_LENGTH : MIN_USERNAME_LENGTH;
return username.length >= minUsernameLength
&& username.length <= MAX_USERNAME_LENGTH
&& USERNAME_REGEX.test(username);
}