diff --git a/ruma-identifiers-macros/Cargo.toml b/ruma-identifiers-macros/Cargo.toml index 3c897f4b..8f8c7be8 100644 --- a/ruma-identifiers-macros/Cargo.toml +++ b/ruma-identifiers-macros/Cargo.toml @@ -10,7 +10,7 @@ version = "0.18.1" edition = "2018" [dependencies] -ruma-identifiers-validation = { version = "0.2.2", path = "../ruma-identifiers-validation", default-features = false } +ruma-identifiers-validation = { version = "0.2.3", path = "../ruma-identifiers-validation", default-features = false } quote = "1.0.8" proc-macro2 = "1.0.24" syn = "1.0.55" diff --git a/ruma-identifiers-validation/CHANGELOG.md b/ruma-identifiers-validation/CHANGELOG.md index 9b81cebf..37997d6b 100644 --- a/ruma-identifiers-validation/CHANGELOG.md +++ b/ruma-identifiers-validation/CHANGELOG.md @@ -1,3 +1,11 @@ +# 0.2.3 + +Improvements: + +* Add a `compat` feature + * Under this feature, more user IDs are accepted that exist in the while but are not + spec-compliant + # 0.2.2 Improvements: diff --git a/ruma-identifiers-validation/Cargo.toml b/ruma-identifiers-validation/Cargo.toml index 2c94fb8e..b9b267f9 100644 --- a/ruma-identifiers-validation/Cargo.toml +++ b/ruma-identifiers-validation/Cargo.toml @@ -8,5 +8,8 @@ authors = [ "Jonas Platte ", ] license = "MIT" -version = "0.2.2" +version = "0.2.3" edition = "2018" + +[features] +compat = [] diff --git a/ruma-identifiers-validation/src/user_id.rs b/ruma-identifiers-validation/src/user_id.rs index c76938e2..ae20f814 100644 --- a/ruma-identifiers-validation/src/user_id.rs +++ b/ruma-identifiers-validation/src/user_id.rs @@ -14,6 +14,11 @@ pub fn validate(s: &str) -> Result<(NonZeroU8, bool), Error> { /// /// Returns an `Err` for invalid user ID localparts, `Ok(false)` for historical user ID localparts /// and `Ok(true)` for fully conforming user ID localparts. +/// +/// With the `compat` feature enabled, this will also return `Ok(false)` for invalid user ID +/// localparts. User IDs that don't even meet the historical user ID restrictions exist in the wild +/// due to Synapse allowing them over federation. This will likely be fixed in an upcoming room +/// version; see . pub fn localpart_is_fully_comforming(localpart: &str) -> Result { // See https://matrix.org/docs/spec/appendices#user-identifiers let is_fully_conforming = localpart @@ -23,9 +28,13 @@ pub fn localpart_is_fully_comforming(localpart: &str) -> Result { // If it's not fully conforming, check if it contains characters that are also disallowed // for historical user IDs. If there are, return an error. // See https://matrix.org/docs/spec/appendices#historical-user-ids + #[cfg(not(feature = "compat"))] if !is_fully_conforming && localpart.bytes().any(|b| b < 0x21 || b == b':' || b > 0x7E) { Err(Error::InvalidCharacters) } else { Ok(is_fully_conforming) } + + #[cfg(feature = "compat")] + Ok(is_fully_conforming) } diff --git a/ruma-identifiers/CHANGELOG.md b/ruma-identifiers/CHANGELOG.md index 1b2381bc..eb837c86 100644 --- a/ruma-identifiers/CHANGELOG.md +++ b/ruma-identifiers/CHANGELOG.md @@ -7,6 +7,12 @@ Breaking changes: * Use `MxcUri::is_valid` to make sure it is spec-compliant * `MxcUri::{media_id, server_name}` return `Some({value})` only if the URI is spec-compliant +Improvements + +* Add a `compat` feature + * Under this feature, more user IDs are accepted that exist in the while but are not + spec-compliant + # 0.18.1 Improvements: diff --git a/ruma-identifiers/Cargo.toml b/ruma-identifiers/Cargo.toml index 810bc9ab..744cbe57 100644 --- a/ruma-identifiers/Cargo.toml +++ b/ruma-identifiers/Cargo.toml @@ -20,6 +20,7 @@ rustdoc-args = ["--cfg", "docsrs"] [features] default = ["serde"] +compat = ["ruma-identifiers-validation/compat"] serde = ["ruma-serde", "serde1"] [dependencies] @@ -27,7 +28,7 @@ either = { version = "1.6.1", optional = true } paste = "1.0.4" rand = { version = "0.8.0", optional = true } ruma-identifiers-macros = { version = "=0.18.1", path = "../ruma-identifiers-macros" } -ruma-identifiers-validation = { version = "0.2.2", path = "../ruma-identifiers-validation", default-features = false } +ruma-identifiers-validation = { version = "0.2.3", path = "../ruma-identifiers-validation", default-features = false } ruma-serde = { version = "0.3.1", path = "../ruma-serde", optional = true } ruma-serde-macros = { version = "0.3.1", path = "../ruma-serde-macros" } # Renamed so we can have a serde feature. diff --git a/ruma-identifiers/src/user_id.rs b/ruma-identifiers/src/user_id.rs index 10e885ae..f172707c 100644 --- a/ruma-identifiers/src/user_id.rs +++ b/ruma-identifiers/src/user_id.rs @@ -239,6 +239,7 @@ mod tests { } #[test] + #[cfg(not(feature = "compat"))] fn invalid_characters_in_user_id_localpart() { assert_eq!(UserId::try_from("@te\nst:example.com").unwrap_err(), Error::InvalidCharacters); } diff --git a/ruma/Cargo.toml b/ruma/Cargo.toml index 654ce297..f1f4d2ad 100644 --- a/ruma/Cargo.toml +++ b/ruma/Cargo.toml @@ -86,7 +86,12 @@ full = [ # # For example, some mandatory string fields are defaulted to an empty string if # missing with this feature. -compat = ["ruma-common/compat", "ruma-events/compat", "ruma-client-api/compat"] +compat = [ + "ruma-common/compat", + "ruma-events/compat", + "ruma-identifiers/compat", + "ruma-client-api/compat", +] # unstable: by using any of these, you opt out of all semver guarantees Ruma # otherwise provides!