Merge pull request #3 from matrix-org/main

sync to upstream
This commit is contained in:
Dome
2026-04-07 17:28:24 +02:00
committed by GitHub
3 changed files with 15 additions and 5 deletions
+2
View File
@@ -56,6 +56,8 @@ The matrix.to URL scheme is
The #/ component is mandatory and exists to avoid leaking the target URL to the The #/ component is mandatory and exists to avoid leaking the target URL to the
server hosting matrix.to. server hosting matrix.to.
There is no _Entity type_ for **Spaces**, as they are technically just rooms.
Note that linking to rooms by ID should only be used for rooms to which the Note that linking to rooms by ID should only be used for rooms to which the
target user has been invited: these links cannot be assumed to work for all target user has been invited: these links cannot be assumed to work for all
visitors. visitors.
+12 -5
View File
@@ -18,7 +18,7 @@ import {createEnum} from "./utils/enum.js";
import {orderedUnique} from "./utils/unique.js"; import {orderedUnique} from "./utils/unique.js";
const ROOMALIAS_PATTERN = /^#([^:]*):(.+)$/; const ROOMALIAS_PATTERN = /^#([^:]*):(.+)$/;
const ROOMID_PATTERN = /^!([^:]*):(.+)$/; const ROOMID_PATTERN = /^!([^:]*)(:(.+))?$/; // As of room version 12, room IDs don't have domains
const USERID_PATTERN = /^@([^:]+):(.+)$/; const USERID_PATTERN = /^@([^:]+):(.+)$/;
const EVENTID_PATTERN = /^$([^:]+):(.+)$/; const EVENTID_PATTERN = /^$([^:]+):(.+)$/;
const GROUPID_PATTERN = /^\+([^:]+):(.+)$/; const GROUPID_PATTERN = /^\+([^:]+):(.+)$/;
@@ -92,7 +92,7 @@ export class Link {
static validateIdentifier(identifier) { static validateIdentifier(identifier) {
return !!( return !!(
USERID_PATTERN.exec(identifier) || USERID_PATTERN.exec(identifier) ||
ROOMALIAS_PATTERN.exec(identifier) || ROOMALIAS_PATTERN.exec(identifier) ||
ROOMID_PATTERN.exec(identifier) || ROOMID_PATTERN.exec(identifier) ||
GROUPID_PATTERN.exec(identifier) GROUPID_PATTERN.exec(identifier)
); );
@@ -152,7 +152,7 @@ export class Link {
} }
matches = ROOMID_PATTERN.exec(identifier); matches = ROOMID_PATTERN.exec(identifier);
if (matches) { if (matches) {
const server = matches[2]; const server = matches[3]; // group 2 is an optional over `:domain`, group 3 is just `domain`
const localPart = matches[1]; const localPart = matches[1];
return new Link(clientId, viaServers, IdentifierKind.RoomId, localPart, server, webInstances, eventId); return new Link(clientId, viaServers, IdentifierKind.RoomId, localPart, server, webInstances, eventId);
} }
@@ -166,12 +166,19 @@ export class Link {
} }
constructor(clientId, viaServers, identifierKind, localPart, server, webInstances, eventId) { constructor(clientId, viaServers, identifierKind, localPart, server, webInstances, eventId) {
const servers = [server]; const servers = [];
if (server !== undefined) {
servers.push(server); // v12 rooms don't have domains, and therefore no server
}
servers.push(...viaServers); servers.push(...viaServers);
this.webInstances = webInstances; this.webInstances = webInstances;
this.servers = orderedUnique(servers); this.servers = orderedUnique(servers);
this.identifierKind = identifierKind; this.identifierKind = identifierKind;
this.identifier = `${asPrefix(identifierKind)}${localPart}:${server}`; if (identifierKind === IdentifierKind.RoomId && !server) {
this.identifier = `${asPrefix(identifierKind)}${localPart}`;
} else {
this.identifier = `${asPrefix(identifierKind)}${localPart}:${server}`;
}
this.eventId = eventId; this.eventId = eventId;
this.clientId = clientId; this.clientId = clientId;
} }
+1
View File
@@ -25,6 +25,7 @@ const trustedWebInstances = [
"chat.mozilla.org", "chat.mozilla.org",
"webchat.kde.org", "webchat.kde.org",
"app.gitter.im", "app.gitter.im",
"chat.blender.org",
]; ];
/** /**