Add external-link validation before setting
This commit is contained in:
parent
695ee9df9b
commit
086ad0ec69
2 changed files with 8 additions and 0 deletions
|
@ -11,6 +11,7 @@ pub enum LinkErrorKind {
|
|||
ExistingLinkTypeWrong,
|
||||
LinkTargetDoesNotExist,
|
||||
InternalConversionError,
|
||||
InvalidUri,
|
||||
}
|
||||
|
||||
fn link_error_type_as_str(e: &LinkErrorKind) -> &'static str {
|
||||
|
@ -29,6 +30,9 @@ fn link_error_type_as_str(e: &LinkErrorKind) -> &'static str {
|
|||
|
||||
&LinkErrorKind::InternalConversionError
|
||||
=> "Error while converting values internally",
|
||||
|
||||
&LinkErrorKind::InvalidUri
|
||||
=> "URI is not valid",
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -100,6 +100,10 @@ impl ExternalLinker for EntryHeader {
|
|||
///
|
||||
/// Return the previous set link if there was any
|
||||
fn set_external_link(&mut self, l: Link) -> Result<Option<Link>> {
|
||||
if !l.is_valid() {
|
||||
return Err(LinkError::new(LinkErrorKind::InvalidUri, None));
|
||||
}
|
||||
|
||||
let old_link = self.set("imag.content.uri", Value::String(l.into()));
|
||||
|
||||
if old_link.is_err() {
|
||||
|
|
Loading…
Reference in a new issue