fix: treat matrix links as regular web urls. Closes #3329

This commit is contained in:
Gabe Kangas 2024-01-21 20:22:13 -08:00
parent f9915c9a72
commit 2b57741397
No known key found for this signature in database
GPG key ID: 4345B2060657F330
3 changed files with 1 additions and 47 deletions

View file

@ -14,7 +14,6 @@ import {
} from '../../../../utils/config-constants'; } from '../../../../utils/config-constants';
import { SocialHandle, UpdateArgs } from '../../../../types/config-section'; import { SocialHandle, UpdateArgs } from '../../../../types/config-section';
import { import {
isValidMatrixAccount,
isValidAccount, isValidAccount,
isValidUrl, isValidUrl,
DEFAULT_TEXTFIELD_URL_PATTERN, DEFAULT_TEXTFIELD_URL_PATTERN,
@ -294,9 +293,6 @@ export default function EditSocialLinks() {
if (platform === 'xmpp') { if (platform === 'xmpp') {
return isValidAccount(url, 'xmpp'); return isValidAccount(url, 'xmpp');
} }
if (platform === 'matrix') {
return isValidMatrixAccount(url);
}
return isValidUrl(url); return isValidUrl(url);
}; };

View file

@ -1,4 +1,4 @@
import { isValidUrl, isValidAccount, isValidMatrixAccount } from '../utils/validators'; import { isValidUrl, isValidAccount } from '../utils/validators';
describe('test url validation', () => { describe('test url validation', () => {
const validURL = 'https://example.com'; const validURL = 'https://example.com';
@ -25,18 +25,3 @@ describe('test xmpp account validation', () => {
expect(isValidAccount(invalidAccount, 'xmpp')).toBe(false); 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);
});
});

View file

@ -52,33 +52,6 @@ export function isValidAccount(account: string, protocol: string): boolean {
return true; 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. * Determines if a fediverse account is valid.
* For example: @username@example.com * For example: @username@example.com