From 40aa38a6acb39e34cb891e716c6b46bbd259d90d Mon Sep 17 00:00:00 2001 From: dualfroz Date: Fri, 4 Sep 2026 09:35:35 +0200 Subject: [PATCH] fix(validation): allow image height up to spec maximum of 400 Image height was validated against 0..=144, the same bound as width, but the RSS 2.0 specification allows heights up to 400 (width max is 144). Spec-valid images with a height between 145 and 400 were wrongly reported as invalid. Validate height against 0..=400 and fix the error message. --- src/validation.rs | 4 ++-- tests/validation.rs | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 tests/validation.rs diff --git a/src/validation.rs b/src/validation.rs index 2f19ab0..2ccf7dc 100644 --- a/src/validation.rs +++ b/src/validation.rs @@ -222,8 +222,8 @@ impl Validate for Image { if let Some(height) = self.height() { let height = height.parse::()?; validate!( - (0..=144).contains(&height), - "Image height is not between 0 and 144" + (0..=400).contains(&height), + "Image height is not between 0 and 400" ); } diff --git a/tests/validation.rs b/tests/validation.rs new file mode 100644 index 0000000..b68e360 --- /dev/null +++ b/tests/validation.rs @@ -0,0 +1,42 @@ +#![cfg(feature = "validation")] + +use rss::validation::Validate; +use rss::ImageBuilder; + +fn image_with_height(height: &str) -> rss::Image { + ImageBuilder::default() + .url("https://example.com/image.png".to_string()) + .link("https://example.com/".to_string()) + .title("title".to_string()) + .height(height.to_string()) + .build() +} + +fn image_with_width(width: &str) -> rss::Image { + ImageBuilder::default() + .url("https://example.com/image.png".to_string()) + .link("https://example.com/".to_string()) + .title("title".to_string()) + .width(width.to_string()) + .build() +} + +#[test] +fn image_height_allows_up_to_400() { + // The RSS 2.0 specification sets the maximum image height to 400. + assert!(image_with_height("31").validate().is_ok()); + assert!(image_with_height("200").validate().is_ok()); + assert!(image_with_height("400").validate().is_ok()); +} + +#[test] +fn image_height_above_400_is_invalid() { + assert!(image_with_height("401").validate().is_err()); +} + +#[test] +fn image_width_max_is_still_144() { + // Width keeps its specification maximum of 144. + assert!(image_with_width("144").validate().is_ok()); + assert!(image_with_width("145").validate().is_err()); +}