From 3e85f65d9e7a5b3a64091e061ff1137a9b58fcab Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Sat, 29 Feb 2020 00:36:01 +0000 Subject: [PATCH] Also skip alias availability check if alias looks invalid Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/components/views/elements/RoomAliasField.js | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/components/views/elements/RoomAliasField.js b/src/components/views/elements/RoomAliasField.js index 0139a9596b..06e608b14c 100644 --- a/src/components/views/elements/RoomAliasField.js +++ b/src/components/views/elements/RoomAliasField.js @@ -38,6 +38,13 @@ export default class RoomAliasField extends React.PureComponent { return `#${localpart}:${this.props.domain}`; } + _isValid(value) { + const fullAlias = this._asFullAlias(value); + // XXX: FIXME https://github.com/matrix-org/matrix-doc/issues/668 + return !value.includes("#") && !value.includes(":") && !value.includes(",") && + encodeURI(fullAlias) === fullAlias; + } + render() { const Field = sdk.getComponent('views.elements.Field'); const poundSign = (#); @@ -80,10 +87,7 @@ export default class RoomAliasField extends React.PureComponent { if (!value) { return true; } - const fullAlias = this._asFullAlias(value); - // XXX: FIXME https://github.com/matrix-org/matrix-doc/issues/668 - return !value.includes("#") && !value.includes(":") && !value.includes(",") && - encodeURI(fullAlias) === fullAlias; + return this._isValid(value); }, invalid: () => _t("Some characters not allowed"), }, { @@ -92,7 +96,7 @@ export default class RoomAliasField extends React.PureComponent { invalid: () => _t("Please provide a room alias"), }, { key: "taken", - skip: ({value}) => !value, + skip: ({value}) => !value || !this._isValid(value), test: async ({value}) => { if (!value) { return true;