identifiers-validation: Allow + in the localpart of user IDs

According to MSC4009
This commit is contained in:
Kévin Commaille 2023-08-21 10:57:07 +02:00 committed by Kévin Commaille
parent a9a6e67ed0
commit 8bdfd809e4
2 changed files with 9 additions and 3 deletions

View File

@ -1,9 +1,15 @@
# [unreleased]
Bug fixes:
- Don't consider empty localpart of a user ID as valid
- It is accepted under the `compat-user-id` feature, but not considered
fully-conforming
Improvements:
- Allow `+` in the localpart of user IDs according to MSC4009
# 0.9.1
Improvements:

View File

@ -20,9 +20,9 @@ pub fn validate(s: &str) -> Result<(), Error> {
pub fn localpart_is_fully_conforming(localpart: &str) -> Result<bool, Error> {
// See https://spec.matrix.org/latest/appendices/#user-identifiers
let is_fully_conforming = !localpart.is_empty()
&& localpart
.bytes()
.all(|b| matches!(b, b'0'..=b'9' | b'a'..=b'z' | b'-' | b'.' | b'=' | b'_' | b'/'));
&& localpart.bytes().all(
|b| matches!(b, b'0'..=b'9' | b'a'..=b'z' | b'-' | b'.' | b'=' | b'_' | b'/' | b'+'),
);
if !is_fully_conforming {
// If it's not fully conforming, check if it contains characters that are also disallowed