identifiers: Fix MXC URI validation
This commit is contained in:
		
							parent
							
								
									3997e445b5
								
							
						
					
					
						commit
						b2c3df421d
					
				@ -1,5 +1,13 @@
 | 
				
			|||||||
# [unreleased]
 | 
					# [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:
 | 
					Improvements:
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- Point links to the Matrix 1.9 specification
 | 
					- 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 server_name = &uri[..index];
 | 
				
			||||||
    let media_id = &uri[index + 1..];
 | 
					    let media_id = &uri[index + 1..];
 | 
				
			||||||
    // See: https://spec.matrix.org/v1.9/client-server-api/#security-considerations-5
 | 
					    // See: https://spec.matrix.org/v1.9/client-server-api/#security-considerations-5
 | 
				
			||||||
    let media_id_is_valid =
 | 
					    let media_id_is_valid = media_id
 | 
				
			||||||
        media_id.bytes().all(|b| matches!(b, b'0'..=b'9' | b'a'..=b'z' | b'A'..=b'Z' | b'-' ));
 | 
					        .bytes()
 | 
				
			||||||
 | 
					        .all(|b| matches!(b, b'0'..=b'9' | b'a'..=b'z' | b'A'..=b'Z' | b'-' | b'_' ));
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if !media_id_is_valid {
 | 
					    if !media_id_is_valid {
 | 
				
			||||||
        Err(MxcUriError::MediaIdMalformed)
 | 
					        Err(MxcUriError::MediaIdMalformed)
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user