[librsvg] impl Error for AllowedUrlError



commit f01ab6ad201edf5668307db0a0ac4da9a2953432
Author: Federico Mena Quintero <federico gnome org>
Date:   Wed Nov 28 14:05:44 2018 -0600

    impl Error for AllowedUrlError

 rsvg_internals/src/allowed_url.rs | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
---
diff --git a/rsvg_internals/src/allowed_url.rs b/rsvg_internals/src/allowed_url.rs
index d6b69692..53c00595 100644
--- a/rsvg_internals/src/allowed_url.rs
+++ b/rsvg_internals/src/allowed_url.rs
@@ -1,3 +1,5 @@
+use std::error::{self, Error};
+use std::fmt;
 use std::io;
 use std::path::{Path, PathBuf};
 use url::{self, Url};
@@ -108,6 +110,30 @@ impl AllowedUrl {
     }
 }
 
+impl error::Error for AllowedUrlError {
+    fn description(&self) -> &str {
+        match *self {
+            AllowedUrlError::HrefParseError(_) => "href parse error",
+            AllowedUrlError::BaseRequired => "base required",
+            AllowedUrlError::DifferentURISchemes => "different URI schemes",
+            AllowedUrlError::DisallowedScheme => "disallowed scheme",
+            AllowedUrlError::NotSiblingOrChildOfBaseFile => "not sibling or child of base file",
+            AllowedUrlError::InvalidPath => "invalid path",
+            AllowedUrlError::BaseIsRoot => "base is root",
+            AllowedUrlError::CanonicalizationError => "canonicalization error",
+        }
+    }
+}
+
+impl fmt::Display for AllowedUrlError {
+    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+        match *self {
+            AllowedUrlError::HrefParseError(e) => write!(f, "{}: {}", self.description(), e),
+            _ => write!(f, "{}", self.description()),
+        }
+    }
+}
+
 // For tests, we don't want to touch the filesystem.  In that case,
 // assume that we are being passed canonical file names.
 #[cfg(not(test))]


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]