[librsvg: 2/3] allowed_url: implement deref
- From: Federico Mena Quintero <federico src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [librsvg: 2/3] allowed_url: implement deref
- Date: Mon, 14 Jan 2019 23:47:33 +0000 (UTC)
commit a7fc45474915826eb3428666637462f19da871b3
Author: Paolo Borelli <pborelli gnome org>
Date: Mon Jan 14 22:25:34 2019 +0100
allowed_url: implement deref
Since this is a validated wrapper around Url, dereferencing the
actual Url is handy
rsvg_internals/src/allowed_url.rs | 23 ++++++++++++++---------
rsvg_internals/src/css.rs | 8 ++++----
rsvg_internals/src/handle.rs | 2 +-
rsvg_internals/src/io.rs | 4 ++--
rsvg_internals/src/xml.rs | 8 ++++----
5 files changed, 25 insertions(+), 20 deletions(-)
---
diff --git a/rsvg_internals/src/allowed_url.rs b/rsvg_internals/src/allowed_url.rs
index 561b0b80..662493f1 100644
--- a/rsvg_internals/src/allowed_url.rs
+++ b/rsvg_internals/src/allowed_url.rs
@@ -1,6 +1,7 @@
use std::error::{self, Error};
use std::fmt;
use std::io;
+use std::ops::Deref;
use std::path::{Path, PathBuf};
use url::{self, Url};
@@ -106,8 +107,12 @@ impl AllowedUrl {
Err(AllowedUrlError::NotSiblingOrChildOfBaseFile)
}
}
+}
+
+impl Deref for AllowedUrl {
+ type Target = Url;
- pub fn url(&self) -> &Url {
+ fn deref(&self) -> &Url {
&self.0
}
}
@@ -303,8 +308,8 @@ mod tests {
assert_eq!(
AllowedUrl::from_href("data:image/jpeg;base64,xxyyzz", None)
.unwrap()
- .url(),
- &Url::parse("data:image/jpeg;base64,xxyyzz").unwrap(),
+ .as_ref(),
+ "data:image/jpeg;base64,xxyyzz",
);
}
@@ -316,8 +321,8 @@ mod tests {
Some(Url::parse("file:///example/bar.svg").unwrap()).as_ref()
)
.unwrap()
- .url(),
- &Url::parse("file:///example/foo.svg").unwrap(),
+ .as_ref(),
+ "file:///example/foo.svg",
);
}
@@ -329,8 +334,8 @@ mod tests {
Some(Url::parse("file:///example/bar.svg").unwrap()).as_ref()
)
.unwrap()
- .url(),
- &Url::parse("file:///example/foo.svg").unwrap(),
+ .as_ref(),
+ "file:///example/foo.svg",
);
}
@@ -342,8 +347,8 @@ mod tests {
Some(Url::parse("file:///example/bar.svg").unwrap()).as_ref()
)
.unwrap()
- .url(),
- &Url::parse("file:///example/subdir/foo.svg").unwrap(),
+ .as_ref(),
+ "file:///example/subdir/foo.svg",
);
}
diff --git a/rsvg_internals/src/css.rs b/rsvg_internals/src/css.rs
index 8cb0129f..d0cbb4e4 100644
--- a/rsvg_internals/src/css.rs
+++ b/rsvg_internals/src/css.rs
@@ -36,7 +36,7 @@ impl CssStyles {
}
}
- pub fn parse(&mut self, base_url: Option<Url>, buf: &str) {
+ pub fn parse(&mut self, base_url: Option<&Url>, buf: &str) {
if buf.len() == 0 {
return; // libcroco doesn't like empty strings :(
}
@@ -97,7 +97,7 @@ impl CssStyles {
})
})
.and_then(|utf8| {
- self.parse(Some(aurl.url().clone()), &utf8);
+ self.parse(Some(&aurl), &utf8);
Ok(()) // FIXME: return CSS parsing errors
})
}
@@ -148,7 +148,7 @@ impl CssStyles {
}
struct DocHandlerData<'a> {
- base_url: Option<Url>,
+ base_url: Option<&'a Url>,
css_styles: &'a mut CssStyles,
selector: *mut CRSelector,
}
@@ -184,7 +184,7 @@ unsafe extern "C" fn css_import_style(
let raw_uri = cr_string_peek_raw_str(a_uri);
let uri = utf8_cstr(raw_uri);
- if let Ok(aurl) = AllowedUrl::from_href(uri, handler_data.base_url.as_ref()) {
+ if let Ok(aurl) = AllowedUrl::from_href(uri, handler_data.base_url) {
// FIXME: handle CSS errors
let _ = handler_data.css_styles.load_css(&aurl);
} else {
diff --git a/rsvg_internals/src/handle.rs b/rsvg_internals/src/handle.rs
index 4eec6f9a..7f0305b8 100644
--- a/rsvg_internals/src/handle.rs
+++ b/rsvg_internals/src/handle.rs
@@ -588,7 +588,7 @@ pub fn lookup_fragment_id(handle: *const RsvgHandle, id: &str) -> Option<Rc<Node
pub fn load_extern(load_options: &LoadOptions, aurl: &AllowedUrl) -> Result<*mut RsvgHandle, ()> {
unsafe {
- let file = gio::File::new_for_uri(aurl.url().as_str());
+ let file = gio::File::new_for_uri(aurl.as_str());
let res = rsvg_handle_new_from_gfile_sync(
file.to_glib_none().0,
diff --git a/rsvg_internals/src/io.rs b/rsvg_internals/src/io.rs
index ea8a66a9..48efb4ef 100644
--- a/rsvg_internals/src/io.rs
+++ b/rsvg_internals/src/io.rs
@@ -80,7 +80,7 @@ pub fn acquire_stream(
aurl: &AllowedUrl,
cancellable: Option<&Cancellable>,
) -> Result<InputStream, LoadingError> {
- let uri = aurl.url().as_str();
+ let uri = aurl.as_str();
if uri.starts_with("data:") {
let BinaryData { data, .. } = decode_data_uri(uri)?;
@@ -100,7 +100,7 @@ pub fn acquire_data(
aurl: &AllowedUrl,
cancellable: Option<&Cancellable>,
) -> Result<BinaryData, LoadingError> {
- let uri = aurl.url().as_str();
+ let uri = aurl.as_str();
if uri.starts_with("data:") {
Ok(decode_data_uri(uri)?)
diff --git a/rsvg_internals/src/xml.rs b/rsvg_internals/src/xml.rs
index 3d6dd20f..8051a591 100644
--- a/rsvg_internals/src/xml.rs
+++ b/rsvg_internals/src/xml.rs
@@ -277,7 +277,7 @@ impl XmlState {
let css_styles = self.css_styles.as_mut().unwrap();
- css_styles.parse(self.load_options.base_url.clone(), &css_data);
+ css_styles.parse(self.load_options.base_url.as_ref(), &css_data);
}
self.current_node = node.get_parent();
@@ -445,14 +445,14 @@ impl XmlState {
encoding: Option<&str>,
) -> Result<(), AcquireError> {
let binary = io::acquire_data(aurl, None).map_err(|e| {
- rsvg_log!("could not acquire \"{}\": {}", aurl.url(), e);
+ rsvg_log!("could not acquire \"{}\": {}", aurl, e);
AcquireError::ResourceError
})?;
let encoding = encoding.unwrap_or("utf-8");
let encoder = encoding_from_whatwg_label(encoding).ok_or_else(|| {
- rsvg_log!("unknown encoding \"{}\" for \"{}\"", encoding, aurl.url());
+ rsvg_log!("unknown encoding \"{}\" for \"{}\"", encoding, aurl);
AcquireError::FatalError
})?;
@@ -461,7 +461,7 @@ impl XmlState {
.map_err(|e| {
rsvg_log!(
"could not convert contents of \"{}\" from character encoding \"{}\": {}",
- aurl.url(),
+ aurl,
encoding,
e
);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]