From ee820b6ca1f45f317b1fa301767181a078f427f6 Mon Sep 17 00:00:00 2001 From: Danila Fedorin Date: Tue, 24 Aug 2021 13:32:36 -0700 Subject: [PATCH] URLencode identifiers --- src/Link.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Link.js b/src/Link.js index a37cfc8..1f72be6 100644 --- a/src/Link.js +++ b/src/Link.js @@ -30,6 +30,10 @@ export const IdentifierKind = createEnum( "GroupId", ); +function idToPath(identifier) { + return encodeURIComponent(identifier.substring(1)); +} + function asPrefix(identifierKind) { switch (identifierKind) { case IdentifierKind.RoomId: return "!"; @@ -200,8 +204,8 @@ export class Link { // Some matrix.to links aren't valid matrix: links (i.e. groups) return null; } - const identifier = this.identifier.substring(1); - const suffix = this.eventId ? `/e/${this.eventId.substring(1)}` : ""; + const identifier = idToPath(this.identifier); + const suffix = this.eventId ? `/e/${idToPath(this.eventId)}` : ""; return `matrix:${prefix}/${identifier}${suffix}`; } }