new functions and fixes

This commit is contained in:
Mateusz Gruszczyński
2026-08-05 22:13:04 +02:00
parent 9fc32d0d31
commit e842b26978
34 changed files with 2505 additions and 115 deletions
+31 -1
View File
@@ -7,7 +7,10 @@
* See LICENSE file in repository root for details.
*/
use super::{content_references_file, content_references_stored_file, is_safe_inline_image_mime};
use super::{
content_references_file, content_references_stored_file, is_safe_inline_image_mime,
is_safe_inline_video_mime, parse_byte_range,
};
#[test]
fn only_raster_images_are_inline() {
@@ -48,3 +51,30 @@ fn attachment_references_survive_origin_changes() {
Some("https://new-files.example.com"),
));
}
#[test]
fn common_video_formats_are_inline() {
assert!(is_safe_inline_video_mime("video/mp4"));
assert!(is_safe_inline_video_mime("video/webm"));
assert!(!is_safe_inline_video_mime("text/html"));
assert!(!is_safe_inline_video_mime("application/javascript"));
}
#[test]
fn video_alias_is_still_attached() {
assert!(content_references_file(
"[video=clip.mp4,Product demo]",
"clip.mp4",
"/f/token/clip.mp4",
));
}
#[test]
fn byte_ranges_support_video_seeking() {
assert_eq!(parse_byte_range("bytes=0-99", 1_000), Ok(Some((0, 100))));
assert_eq!(parse_byte_range("bytes=500-", 1_000), Ok(Some((500, 1_000))));
assert_eq!(parse_byte_range("bytes=-100", 1_000), Ok(Some((900, 1_000))));
assert_eq!(parse_byte_range("bytes=900-2000", 1_000), Ok(Some((900, 1_000))));
assert_eq!(parse_byte_range("bytes=1000-", 1_000), Err(()));
assert_eq!(parse_byte_range("bytes=0-1,4-5", 1_000), Err(()));
}