Also skip alias availability check if alias looks invalid

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
pull/21833/head
Michael Telatynski 2020-02-29 00:36:01 +00:00
parent 86a1327259
commit 3e85f65d9e
1 changed files with 9 additions and 5 deletions

View File

@ -38,6 +38,13 @@ export default class RoomAliasField extends React.PureComponent {
return `#${localpart}:${this.props.domain}`; 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() { render() {
const Field = sdk.getComponent('views.elements.Field'); const Field = sdk.getComponent('views.elements.Field');
const poundSign = (<span>#</span>); const poundSign = (<span>#</span>);
@ -80,10 +87,7 @@ export default class RoomAliasField extends React.PureComponent {
if (!value) { if (!value) {
return true; return true;
} }
const fullAlias = this._asFullAlias(value); return this._isValid(value);
// XXX: FIXME https://github.com/matrix-org/matrix-doc/issues/668
return !value.includes("#") && !value.includes(":") && !value.includes(",") &&
encodeURI(fullAlias) === fullAlias;
}, },
invalid: () => _t("Some characters not allowed"), invalid: () => _t("Some characters not allowed"),
}, { }, {
@ -92,7 +96,7 @@ export default class RoomAliasField extends React.PureComponent {
invalid: () => _t("Please provide a room alias"), invalid: () => _t("Please provide a room alias"),
}, { }, {
key: "taken", key: "taken",
skip: ({value}) => !value, skip: ({value}) => !value || !this._isValid(value),
test: async ({value}) => { test: async ({value}) => {
if (!value) { if (!value) {
return true; return true;