From 880c3817b7bfa416c2d0836a89a9a10c2f270835 Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Mon, 11 Aug 2025 03:25:16 -0400 Subject: [PATCH 1/7] Don't validate room ID server names for v12 compat --- src/identifiers.rs | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/identifiers.rs b/src/identifiers.rs index 9da69e8..432e561 100644 --- a/src/identifiers.rs +++ b/src/identifiers.rs @@ -210,12 +210,7 @@ impl RoomId { #[napi(constructor, strict)] pub fn new(id: String) -> napi::Result { let room_id = ruma::RoomId::parse(id).map_err(into_err)?; - match room_id.server_name() { - Some(_) => Ok(Self::from(room_id)), - None => Err(napi::Error::from_reason( - "Room ID does not have a valid server_name".to_owned(), - )), - } + Ok(Self::from(room_id)) } /// Return the room ID as a string. @@ -228,7 +223,7 @@ impl RoomId { /// Returns the server name of the room ID. #[napi(getter)] pub fn server_name(&self) -> ServerName { - ServerName { inner: self.inner.server_name().unwrap().to_owned() } + ServerName { inner: self.inner.server_name().unwrap_or(<&ruma::ServerName>::try_from("").unwrap()).to_owned() } } } From 9bd3b0d554ffdcab0949b0a26fbc4719962ade92 Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Mon, 11 Aug 2025 04:00:26 -0400 Subject: [PATCH 2/7] cargo fmt --- src/identifiers.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/identifiers.rs b/src/identifiers.rs index 432e561..cf64efd 100644 --- a/src/identifiers.rs +++ b/src/identifiers.rs @@ -223,7 +223,13 @@ impl RoomId { /// Returns the server name of the room ID. #[napi(getter)] pub fn server_name(&self) -> ServerName { - ServerName { inner: self.inner.server_name().unwrap_or(<&ruma::ServerName>::try_from("").unwrap()).to_owned() } + ServerName { + inner: self + .inner + .server_name() + .unwrap_or(<&ruma::ServerName>::try_from("").unwrap()) + .to_owned(), + } } } From 3f28d0e65ac2833513370bebd0230f3a2d065706 Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Mon, 11 Aug 2025 04:45:34 -0400 Subject: [PATCH 3/7] Make room ID server name optional --- src/identifiers.rs | 13 ++++++------- tests/identifiers.test.js | 8 ++++---- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/identifiers.rs b/src/identifiers.rs index cf64efd..30c775c 100644 --- a/src/identifiers.rs +++ b/src/identifiers.rs @@ -222,13 +222,12 @@ impl RoomId { /// Returns the server name of the room ID. #[napi(getter)] - pub fn server_name(&self) -> ServerName { - ServerName { - inner: self - .inner - .server_name() - .unwrap_or(<&ruma::ServerName>::try_from("").unwrap()) - .to_owned(), + pub fn server_name(&self) -> Option { + match self.inner.server_name() { + Some(server_name) => Some(ServerName { + inner: server_name.to_owned() + }), + None => None, } } } diff --git a/tests/identifiers.test.js b/tests/identifiers.test.js index 831ce4a..4c49c2a 100644 --- a/tests/identifiers.test.js +++ b/tests/identifiers.test.js @@ -87,10 +87,10 @@ describe("DeviceKeyAlgorithmName", () => { }); describe(RoomId.name, () => { - test("cannot be invalid", () => { - expect(() => { - new RoomId("!foo"); - }).toThrow(); + const roomV12 = new RoomId("!foo") + + test("may have no server name", () => { + expect(roomV12.serverName).toStrictEqual(null); }); const room = new RoomId("!foo:bar.org"); From 30c6a64fca526b2d2cf8516f34f40deeccaeb6c4 Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Mon, 11 Aug 2025 04:57:32 -0400 Subject: [PATCH 4/7] cargo fmt --- src/identifiers.rs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/identifiers.rs b/src/identifiers.rs index 30c775c..216ef3a 100644 --- a/src/identifiers.rs +++ b/src/identifiers.rs @@ -224,9 +224,7 @@ impl RoomId { #[napi(getter)] pub fn server_name(&self) -> Option { match self.inner.server_name() { - Some(server_name) => Some(ServerName { - inner: server_name.to_owned() - }), + Some(server_name) => Some(ServerName { inner: server_name.to_owned() }), None => None, } } From 37f2b45530db5112f632d2e68c95c81a23107388 Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Mon, 11 Aug 2025 05:16:11 -0400 Subject: [PATCH 5/7] prettier --- tests/identifiers.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/identifiers.test.js b/tests/identifiers.test.js index 4c49c2a..23556ba 100644 --- a/tests/identifiers.test.js +++ b/tests/identifiers.test.js @@ -87,7 +87,7 @@ describe("DeviceKeyAlgorithmName", () => { }); describe(RoomId.name, () => { - const roomV12 = new RoomId("!foo") + const roomV12 = new RoomId("!foo"); test("may have no server name", () => { expect(roomV12.serverName).toStrictEqual(null); From 5bfd1e8c56538dfd2693d693cd544a595add10f0 Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Mon, 11 Aug 2025 05:52:39 -0400 Subject: [PATCH 6/7] Remove server name property from room IDs entirely as pulling out a server name from room IDs was always inappropriate, as room IDs are meant to be opaque. --- src/identifiers.rs | 9 --------- tests/identifiers.test.js | 18 ++++++------------ 2 files changed, 6 insertions(+), 21 deletions(-) diff --git a/src/identifiers.rs b/src/identifiers.rs index 216ef3a..65f6f3e 100644 --- a/src/identifiers.rs +++ b/src/identifiers.rs @@ -219,15 +219,6 @@ impl RoomId { pub fn to_string(&self) -> String { self.inner.as_str().to_owned() } - - /// Returns the server name of the room ID. - #[napi(getter)] - pub fn server_name(&self) -> Option { - match self.inner.server_name() { - Some(server_name) => Some(ServerName { inner: server_name.to_owned() }), - None => None, - } - } } /// A Matrix-spec compliant [server name]. diff --git a/tests/identifiers.test.js b/tests/identifiers.test.js index 23556ba..78e17f3 100644 --- a/tests/identifiers.test.js +++ b/tests/identifiers.test.js @@ -87,21 +87,15 @@ describe("DeviceKeyAlgorithmName", () => { }); describe(RoomId.name, () => { - const roomV12 = new RoomId("!foo"); - - test("may have no server name", () => { - expect(roomV12.serverName).toStrictEqual(null); - }); - - const room = new RoomId("!foo:bar.org"); - - test("server name is present", () => { - expect(room.serverName).toBeInstanceOf(ServerName); - }); - test("can read the room ID as string", () => { + const room = new RoomId("!foo:bar.org"); expect(room.toString()).toStrictEqual("!foo:bar.org"); }); + + test("can read a room v12 ID as string", () => { + const roomV12 = new RoomId("!foo"); + expect(roomV12.toString()).toStrictEqual("!foo"); + }); }); describe(ServerName.name, () => { From 454636bf719e89f153cb657149e14b24a3b04197 Mon Sep 17 00:00:00 2001 From: Andrew Ferrazzutti Date: Mon, 11 Aug 2025 06:08:03 -0400 Subject: [PATCH 7/7] Mention breaking change in changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7319942..6ffe406 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,8 @@ ## Next release - Update matrix-rust-sdk dependency to 0.9.0. +- `RoomId` no longer has a `serverName` property, and is allowed to not have a server name component. + This is a breaking change. ## 0.3.0-beta.1 - 2024-11-18