Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Fix room alias address isn't checked for validity before being shown as added #7107

Merged
merged 9 commits into from
Jan 4, 2022
15 changes: 9 additions & 6 deletions src/components/views/elements/RoomAliasField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export default class RoomAliasField extends React.PureComponent<IProps, IState>

private validationRules = withValidation({
rules: [
{ key: "hasSingleDomain",
{ key: "hasDomain",
test: async ({ value }) => {
if (!value) {
return true;
Expand All @@ -125,7 +125,7 @@ export default class RoomAliasField extends React.PureComponent<IProps, IState>
invalid: () => _t("Missing domain separator e.g. (:domain.org)"),
},
{
key: "hasMultipleDomains",
key: "hasRoomnameOrAtLeastASingleSeparator",
test: async ({ value }) => {
if (!value) {
return true;
Expand All @@ -135,12 +135,13 @@ export default class RoomAliasField extends React.PureComponent<IProps, IState>
return true;
}
const split = value.split(':');
if (split.length > 2) {
// Define the value invalid if there's no first part (roomname) or separator's missing
if (split.length < 2 || split[0].length < 1) {
t3chguy marked this conversation as resolved.
Show resolved Hide resolved
return false;
}
return true;
},
invalid: () => _t("Multiple domain separators (:) provided, provide an alias with a single domain."),
invalid: () => _t("Missing room name or separator e.g. (my-room:domain.org)"),
},
{
key: "safeLocalpart",
Expand All @@ -152,10 +153,12 @@ export default class RoomAliasField extends React.PureComponent<IProps, IState>
return true;
} else {
const fullAlias = this.asFullAlias(value);
const hasColon = this.props.domain ? !value.includes(":") : true;
// XXX: FIXME https://github.com/matrix-org/matrix-doc/issues/668
// NOTE: We could probably use linkifyjs to parse those aliases here?
return !value.includes("#") &&
this.props.domain ? !value.includes(":") : true &&
!value.includes(",") &&
hasColon &&
!value.includes(",") &&
encodeURI(fullAlias) === fullAlias;
}
},
Expand Down
3 changes: 3 additions & 0 deletions src/i18n/strings/en_EN.json
Original file line number Diff line number Diff line change
Expand Up @@ -2240,10 +2240,13 @@
"In reply to <a>this message</a>": "In reply to <a>this message</a>",
"Room address": "Room address",
"e.g. my-room": "e.g. my-room",
"Missing domain separator e.g. (:domain.org)": "Missing domain separator e.g. (:domain.org)",
"Missing room name or separator e.g. (my-room:domain.org)": "Missing room name or separator e.g. (my-room:domain.org)",
"Some characters not allowed": "Some characters not allowed",
"Please provide an address": "Please provide an address",
"This address is available to use": "This address is available to use",
"This address is already in use": "This address is already in use",
"This address had invalid server or is already in use": "This address had invalid server or is already in use",
"Server Options": "Server Options",
"You can use the custom server options to sign into other Matrix servers by specifying a different homeserver URL. This allows you to use Element with an existing Matrix account on a different homeserver.": "You can use the custom server options to sign into other Matrix servers by specifying a different homeserver URL. This allows you to use Element with an existing Matrix account on a different homeserver.",
"Join millions for free on the largest public server": "Join millions for free on the largest public server",
Expand Down