[librsvg] handle: consolidate allowed url check
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg] handle: consolidate allowed url check
- Date: Mon, 7 Jan 2019 01:24:13 +0000 (UTC)
commit 50703896bf695070743adf183a352e94be69ba85
Author: Paolo Borelli <pborelli gnome org>
Date: Sun Jan 6 14:08:00 2019 +0100
handle: consolidate allowed url check
Do the check in handle instead of the two callers. This also
reduces the uses of handle::get_base_url
rsvg_internals/src/error.rs | 3 +++
rsvg_internals/src/filters/image.rs | 6 +-----
rsvg_internals/src/handle.rs | 7 +++++--
rsvg_internals/src/image.rs | 9 +++------
4 files changed, 12 insertions(+), 13 deletions(-)
---
diff --git a/rsvg_internals/src/error.rs b/rsvg_internals/src/error.rs
index 5c82c96f..4ff45e86 100644
--- a/rsvg_internals/src/error.rs
+++ b/rsvg_internals/src/error.rs
@@ -153,6 +153,7 @@ pub enum LoadingError {
XmlParseError(String),
// Could not parse data: URL
CouldNotCreateXmlParser,
+ BadUrl,
BadDataUrl,
Cairo(cairo::Status),
EmptyData,
@@ -168,6 +169,7 @@ impl error::Error for LoadingError {
LoadingError::NoDataPassedToParser => "no data passed to parser",
LoadingError::CouldNotCreateXmlParser => "could not create XML parser",
LoadingError::XmlParseError(_) => "XML parse error",
+ LoadingError::BadUrl => "invalid URL",
LoadingError::BadDataUrl => "invalid data: URL",
LoadingError::Cairo(_) => "cairo error",
LoadingError::EmptyData => "empty data",
@@ -186,6 +188,7 @@ impl fmt::Display for LoadingError {
LoadingError::XmlParseError(ref s) => write!(f, "XML parse error: {}", s),
LoadingError::NoDataPassedToParser
| LoadingError::CouldNotCreateXmlParser
+ | LoadingError::BadUrl
| LoadingError::BadDataUrl
| LoadingError::EmptyData
| LoadingError::SvgHasNoElements
diff --git a/rsvg_internals/src/filters/image.rs b/rsvg_internals/src/filters/image.rs
index a730414e..771e7dc7 100644
--- a/rsvg_internals/src/filters/image.rs
+++ b/rsvg_internals/src/filters/image.rs
@@ -3,7 +3,6 @@ use std::ptr;
use cairo::{self, ImageSurface, MatrixTrait, PatternTrait};
-use allowed_url::AllowedUrl;
use aspect_ratio::AspectRatio;
use attributes::Attribute;
use defs::{Fragment, Href};
@@ -131,11 +130,8 @@ impl Image {
unreachable!();
};
- let aurl = AllowedUrl::from_href(url, handle::get_base_url(self.handle.get()).as_ref())
- .map_err(|_| FilterError::InvalidInput)?;
-
// FIXME: translate the error better here
- let surface = handle::load_image_to_surface(self.handle.get() as *mut _, &aurl)
+ let surface = handle::load_image_to_surface(self.handle.get() as *mut _, &url)
.map_err(|_| FilterError::InvalidInput)?;
let output_surface = ImageSurface::create(
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index b9e6aeda..1015965f 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -660,11 +660,14 @@ pub fn acquire_stream(
pub fn load_image_to_surface(
handle: *mut RsvgHandle,
- aurl: &AllowedUrl,
+ url: &str,
) -> Result<ImageSurface, LoadingError> {
let rhandle = get_rust_handle(handle);
- let data = acquire_data(handle, aurl)?;
+ let aurl = AllowedUrl::from_href(url, get_base_url(handle).as_ref())
+ .map_err(|_| LoadingError::BadUrl)?;
+
+ let data = acquire_data(handle, &aurl)?;
if data.data.len() == 0 {
return Err(LoadingError::EmptyData);
diff --git a/rsvg_internals/src/image.rs b/rsvg_internals/src/image.rs
index 422ed32a..1da786e5 100644
--- a/rsvg_internals/src/image.rs
+++ b/rsvg_internals/src/image.rs
@@ -2,7 +2,6 @@ use cairo;
use cairo::{MatrixTrait, PatternTrait};
use std::cell::{Cell, RefCell};
-use allowed_url::AllowedUrl;
use aspect_ratio::AspectRatio;
use attributes::Attribute;
use bbox::BoundingBox;
@@ -78,13 +77,11 @@ impl NodeTrait for NodeImage {
_ => unreachable!(),
};
- let aurl = AllowedUrl::from_href(&url, handle::get_base_url(handle).as_ref())
- .map_err(|_| NodeError::value_error(attr, "invalid URL"))?;
-
*self.surface.borrow_mut() = Some(
// FIXME: translate the error better here
- handle::load_image_to_surface(handle as *mut _, &aurl)
- .map_err(|_| NodeError::value_error(attr, "could not load image"))?,
+ handle::load_image_to_surface(handle as *mut _, &url).map_err(|e| {
+ NodeError::value_error(attr, &format!("could not load image: {}", e))
+ })?,
);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]