From 2b5774139789cbe705c867227f11630683cd50ac Mon Sep 17 00:00:00 2001 From: Gabe Kangas Date: Sun, 21 Jan 2024 20:22:13 -0800 Subject: [PATCH] fix: treat matrix links as regular web urls. Closes #3329 --- .../admin/config/general/EditSocialLinks.tsx | 4 --- web/tests/validation.test.ts | 17 +----------- web/utils/validators.ts | 27 ------------------- 3 files changed, 1 insertion(+), 47 deletions(-) diff --git a/web/components/admin/config/general/EditSocialLinks.tsx b/web/components/admin/config/general/EditSocialLinks.tsx index ad000b86d..b1c392ef8 100644 --- a/web/components/admin/config/general/EditSocialLinks.tsx +++ b/web/components/admin/config/general/EditSocialLinks.tsx @@ -14,7 +14,6 @@ import { } from '../../../../utils/config-constants'; import { SocialHandle, UpdateArgs } from '../../../../types/config-section'; import { - isValidMatrixAccount, isValidAccount, isValidUrl, DEFAULT_TEXTFIELD_URL_PATTERN, @@ -294,9 +293,6 @@ export default function EditSocialLinks() { if (platform === 'xmpp') { return isValidAccount(url, 'xmpp'); } - if (platform === 'matrix') { - return isValidMatrixAccount(url); - } return isValidUrl(url); }; diff --git a/web/tests/validation.test.ts b/web/tests/validation.test.ts index 4ba4e2851..c31b54210 100644 --- a/web/tests/validation.test.ts +++ b/web/tests/validation.test.ts @@ -1,4 +1,4 @@ -import { isValidUrl, isValidAccount, isValidMatrixAccount } from '../utils/validators'; +import { isValidUrl, isValidAccount } from '../utils/validators'; describe('test url validation', () => { const validURL = 'https://example.com'; @@ -25,18 +25,3 @@ describe('test xmpp account validation', () => { expect(isValidAccount(invalidAccount, 'xmpp')).toBe(false); }); }); - -describe('test matrix account validation', () => { - const validMatrixAccount = '@me:matrix.org'; - const validMatrixAccountWithProtocol = 'matrix:@me:matrix.org'; - const invalidMatrixAccount = 'something.invalid@something'; - - test('should succeed', () => { - expect(isValidMatrixAccount(validMatrixAccount)).toBe(true); - expect(isValidMatrixAccount(validMatrixAccountWithProtocol)).toBe(true); - }); - - test('should fail', () => { - expect(isValidMatrixAccount(invalidMatrixAccount)).toBe(false); - }); -}); diff --git a/web/utils/validators.ts b/web/utils/validators.ts index 99913ecb0..86b438781 100644 --- a/web/utils/validators.ts +++ b/web/utils/validators.ts @@ -52,33 +52,6 @@ export function isValidAccount(account: string, protocol: string): boolean { return true; } -/** - * Determines if an account is valid by simply checking for a protocol, username - * and server, delimited by a colon. For example: @username:example.com - * @param {string} account - An account to validate. Example: @me:matrix.org - * @returns {boolean} - True if the account is valid, false otherwise. - */ -export function isValidMatrixAccount(account: string): boolean { - if (account.startsWith('matrix:')) { - // eslint-disable-next-line no-param-reassign - account = account.slice(7); - } - - if (account.startsWith('@')) { - // eslint-disable-next-line no-param-reassign - account = account.slice(1); - } - - const components = account.split(':'); - const [user, host] = components; - - if (components.length !== 2 || !user || !host) { - return false; - } - - return true; -} - /** * Determines if a fediverse account is valid. * For example: @username@example.com