identifiers: Fix MXC URI validation
This commit is contained in:
parent
3997e445b5
commit
b2c3df421d
@ -1,5 +1,13 @@
|
||||
# [unreleased]
|
||||
|
||||
Bug fixes:
|
||||
|
||||
- Allow underscores (`_`) when validating MXC URIs.
|
||||
- They have always been allowed in [the spec][mxc validation spec]
|
||||
in order to support URL-safe base64-encoded media IDs.
|
||||
|
||||
[mxc validation spec]: https://spec.matrix.org/v1.9/client-server-api/#security-considerations-5
|
||||
|
||||
Improvements:
|
||||
|
||||
- Point links to the Matrix 1.9 specification
|
||||
|
@ -18,8 +18,9 @@ pub fn validate(uri: &str) -> Result<NonZeroU8, MxcUriError> {
|
||||
let server_name = &uri[..index];
|
||||
let media_id = &uri[index + 1..];
|
||||
// See: https://spec.matrix.org/v1.9/client-server-api/#security-considerations-5
|
||||
let media_id_is_valid =
|
||||
media_id.bytes().all(|b| matches!(b, b'0'..=b'9' | b'a'..=b'z' | b'A'..=b'Z' | b'-' ));
|
||||
let media_id_is_valid = media_id
|
||||
.bytes()
|
||||
.all(|b| matches!(b, b'0'..=b'9' | b'a'..=b'z' | b'A'..=b'Z' | b'-' | b'_' ));
|
||||
|
||||
if !media_id_is_valid {
|
||||
Err(MxcUriError::MediaIdMalformed)
|
||||
|
Loading…
x
Reference in New Issue
Block a user