Add external-link validation before setting

This commit is contained in:
Matthias Beyer 2016-02-23 11:52:31 +01:00
parent 695ee9df9b
commit 086ad0ec69
2 changed files with 8 additions and 0 deletions

View file

@ -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",
}
}

View file

@ -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() {