summaryrefslogtreecommitdiffstats
path: root/libimaglink
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2016-02-23 11:52:31 +0100
committerMatthias Beyer <mail@beyermatthias.de>2016-03-11 15:15:02 +0100
commit086ad0ec692ccac57d92361e204e0a2ad301c357 (patch)
tree21f467aa7872796d0d20f27779a2784efa4327d4 /libimaglink
parent695ee9df9bc24e2cb6f89a49c408fb905e25d2da (diff)
Add external-link validation before setting
Diffstat (limited to 'libimaglink')
-rw-r--r--libimaglink/src/error.rs4
-rw-r--r--libimaglink/src/external.rs4
2 files changed, 8 insertions, 0 deletions
diff --git a/libimaglink/src/error.rs b/libimaglink/src/error.rs
index a57bbbd9..9dfa7533 100644
--- a/libimaglink/src/error.rs
+++ b/libimaglink/src/error.rs
@@ -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",
}
}
diff --git a/libimaglink/src/external.rs b/libimaglink/src/external.rs
index 59d6c0e1..4b5ff81c 100644
--- a/libimaglink/src/external.rs
+++ b/libimaglink/src/external.rs
@@ -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() {