From cad815896b29ac42c69e896fc9ea89c20ee6bf14 Mon Sep 17 00:00:00 2001 From: Cadence Ember Date: Fri, 3 Jul 2026 22:35:10 +1200 Subject: [PATCH] Relax mxc regexp The spec doesn't say which characters are permitted in the opaque ID, but in real life we at least need a hyphen. For lack of a better reference, I copied gomuks. --- src/matrix/api.js | 2 +- src/matrix/utils.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/matrix/api.js b/src/matrix/api.js index 9b7f280..f68380f 100644 --- a/src/matrix/api.js +++ b/src/matrix/api.js @@ -474,7 +474,7 @@ async function ping() { async function getMedia(mxc, init = {}) { init = {...init} - const mediaParts = mxc?.match(/^mxc:\/\/([^/]+)\/(\w+)$/) + const mediaParts = mxc?.match(/^mxc:\/\/([^/]+)\/([a-zA-Z0-9_-]+)$/) assert(mediaParts) let route = "download" diff --git a/src/matrix/utils.js b/src/matrix/utils.js index eee635b..fed71c9 100644 --- a/src/matrix/utils.js +++ b/src/matrix/utils.js @@ -250,7 +250,7 @@ function getPublicUrlForMxc(mxc) { */ function makeMxcPublic(mxc) { assert(hasher, "xxhash is not ready yet") - const mediaParts = mxc?.match(/^mxc:\/\/([^/]+)\/(\w+)$/) + const mediaParts = mxc?.match(/^mxc:\/\/([^/]+)\/([a-zA-Z0-9_-]+)$/) if (!mediaParts) return undefined const serverAndMediaID = `${mediaParts[1]}/${mediaParts[2]}`