Fix parsing encoded matrix.to URL (#660)
authorChuang Zhu <chuang@melty.land>
Mon, 4 Jul 2022 14:20:11 +0000 (22:20 +0800)
committerGitHub <noreply@github.com>
Mon, 4 Jul 2022 14:20:11 +0000 (19:50 +0530)
From https://spec.matrix.org/v1.3/appendices/#matrixto-navigation:

The components of the matrix.to URI (<identifier> and <extra parameter>) are to be percent-encoded as per RFC 3986.

Historically, clients have not produced URIs which are fully encoded. Clients should try to interpret these cases to the best of their ability. For example, an unencoded room alias should still work within the client if possible

src/util/sanitize.js

index 3b230523b6000d6b3c5e1d3627ca88b52c0cf235..5351a1a016e38c4aaf39b51820c22ca26e82bb08 100644 (file)
@@ -44,7 +44,7 @@ function transformSpanTag(tagName, attribs) {
 }
 
 function transformATag(tagName, attribs) {
-  const userLink = attribs.href.match(/^https?:\/\/matrix.to\/#\/(@.+:.+)/);
+  const userLink = decodeURIComponent(attribs.href).match(/^https?:\/\/matrix.to\/#\/(@.+:.+)/);
   if (userLink !== null) {
     // convert user link to pill
     const userId = userLink[1];