URLencode identifiers

This commit is contained in:
Danila Fedorin 2021-08-24 13:32:36 -07:00
parent b8e07cda7e
commit ee820b6ca1

View file

@ -30,6 +30,10 @@ export const IdentifierKind = createEnum(
"GroupId", "GroupId",
); );
function idToPath(identifier) {
return encodeURIComponent(identifier.substring(1));
}
function asPrefix(identifierKind) { function asPrefix(identifierKind) {
switch (identifierKind) { switch (identifierKind) {
case IdentifierKind.RoomId: return "!"; case IdentifierKind.RoomId: return "!";
@ -200,8 +204,8 @@ export class Link {
// Some matrix.to links aren't valid matrix: links (i.e. groups) // Some matrix.to links aren't valid matrix: links (i.e. groups)
return null; return null;
} }
const identifier = this.identifier.substring(1); const identifier = idToPath(this.identifier);
const suffix = this.eventId ? `/e/${this.eventId.substring(1)}` : ""; const suffix = this.eventId ? `/e/${idToPath(this.eventId)}` : "";
return `matrix:${prefix}/${identifier}${suffix}`; return `matrix:${prefix}/${identifier}${suffix}`;
} }
} }