diff --git a/backend/src/s9pk/manifest.rs b/backend/src/s9pk/manifest.rs index 567ec447d..76a190a91 100644 --- a/backend/src/s9pk/manifest.rs +++ b/backend/src/s9pk/manifest.rs @@ -2,6 +2,7 @@ use std::borrow::Borrow; use std::path::{Path, PathBuf}; use std::str::FromStr; +use color_eyre::eyre::eyre; use patch_db::HasModel; use serde::{Deserialize, Serialize, Serializer}; use url::Url; @@ -17,6 +18,7 @@ use crate::status::health_check::HealthChecks; use crate::util::Version; use crate::version::{Current, VersionT}; use crate::volume::Volumes; +use crate::Error; pub const SYSTEM_PACKAGE_ID: PackageId<&'static str> = PackageId(SYSTEM_ID); @@ -210,6 +212,23 @@ pub struct Description { pub short: String, pub long: String, } +impl Description { + pub fn validate(&self) -> Result<(), Error> { + if self.short.chars().skip(160).next().is_some() { + return Err(Error::new( + eyre!("Short description must be 160 characters or less."), + crate::ErrorKind::ValidateS9pk, + )); + } + if self.long.chars().skip(5000).next().is_some() { + return Err(Error::new( + eyre!("Long description must be 5000 characters or less."), + crate::ErrorKind::ValidateS9pk, + )); + } + Ok(()) + } +} #[derive(Clone, Debug, Default, Deserialize, Serialize)] #[serde(rename_all = "kebab-case")] diff --git a/backend/src/s9pk/reader.rs b/backend/src/s9pk/reader.rs index af81811e8..57a78deee 100644 --- a/backend/src/s9pk/reader.rs +++ b/backend/src/s9pk/reader.rs @@ -149,6 +149,7 @@ impl S9pkReader { .into_iter() .map(|i| i.validate(&man.id, &man.version).map(|_| i.image_id)) .collect::, _>>()?; + man.description.validate()?; man.actions .0 .iter()