summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@gnome.org>2022-08-29 20:23:09 -0500
committerFederico Mena Quintero <federico@gnome.org>2022-08-29 20:23:09 -0500
commit20c95d4c9100a81773a19b3337e4e441d7f3b911 (patch)
tree5bee66ea2eb085987ffc777748ed921e7f67e3e5
parentdead6c9bb940b4568dc1f496c2f45c14c7f11e94 (diff)
downloadlibrsvg-20c95d4c9100a81773a19b3337e4e441d7f3b911.tar.gz
XmlState: carry a LoadOptions instead of just its unlimited_size value
Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/738>
-rw-r--r--src/document.rs6
-rw-r--r--src/xml/mod.rs23
2 files changed, 17 insertions, 12 deletions
diff --git a/src/document.rs b/src/document.rs
index 88281a4b..190d6fa4 100644
--- a/src/document.rs
+++ b/src/document.rs
@@ -105,11 +105,9 @@ impl Document {
stream: &gio::InputStream,
cancellable: Option<&gio::Cancellable>,
) -> Result<Document, LoadingError> {
- let unlimited_size = load_options.unlimited_size;
-
xml_load_from_possibly_compressed_stream(
- DocumentBuilder::new(session, load_options),
- unlimited_size,
+ DocumentBuilder::new(session, load_options.clone()),
+ load_options,
stream,
cancellable,
)
diff --git a/src/xml/mod.rs b/src/xml/mod.rs
index ad00710d..ac4529bc 100644
--- a/src/xml/mod.rs
+++ b/src/xml/mod.rs
@@ -16,11 +16,13 @@ use std::collections::HashMap;
use std::rc::{Rc, Weak};
use std::str;
use std::string::ToString;
+use std::sync::Arc;
use xml5ever::tendril::format_tendril;
use xml5ever::tokenizer::{TagKind, Token, TokenSink, XmlTokenizer, XmlTokenizerOpts};
use crate::document::{Document, DocumentBuilder};
use crate::error::{ImplementationLimit, LoadingError};
+use crate::handle::LoadOptions;
use crate::io::{self, IoError};
use crate::limits::MAX_LOADED_ELEMENTS;
use crate::node::{Node, NodeBorrow};
@@ -112,7 +114,7 @@ struct XmlStateInner {
pub struct XmlState {
inner: RefCell<XmlStateInner>,
- unlimited_size: bool,
+ load_options: Arc<LoadOptions>,
}
/// Errors returned from XmlState::acquire()
@@ -135,7 +137,7 @@ impl XmlStateInner {
}
impl XmlState {
- fn new(document_builder: DocumentBuilder, unlimited_size: bool) -> XmlState {
+ fn new(document_builder: DocumentBuilder, load_options: Arc<LoadOptions>) -> XmlState {
XmlState {
inner: RefCell::new(XmlStateInner {
weak: None,
@@ -146,7 +148,7 @@ impl XmlState {
entities: HashMap::new(),
}),
- unlimited_size,
+ load_options,
}
}
@@ -611,9 +613,14 @@ impl XmlState {
.unwrap()
.upgrade()
.unwrap();
- Xml2Parser::from_stream(strong, self.unlimited_size, stream, cancellable)
- .and_then(|parser| parser.parse())
- .and_then(|_: ()| self.check_last_error())
+ Xml2Parser::from_stream(
+ strong,
+ self.load_options.unlimited_size,
+ stream,
+ cancellable,
+ )
+ .and_then(|parser| parser.parse())
+ .and_then(|_: ()| self.check_last_error())
}
fn unsupported_xinclude_start_element(&self, _name: &QualName) -> Context {
@@ -713,11 +720,11 @@ fn parse_xml_stylesheet_processing_instruction(data: &str) -> Result<Vec<(String
pub fn xml_load_from_possibly_compressed_stream(
document_builder: DocumentBuilder,
- unlimited_size: bool,
+ load_options: Arc<LoadOptions>,
stream: &gio::InputStream,
cancellable: Option<&gio::Cancellable>,
) -> Result<Document, LoadingError> {
- let state = Rc::new(XmlState::new(document_builder, unlimited_size));
+ let state = Rc::new(XmlState::new(document_builder, load_options));
state.inner.borrow_mut().weak = Some(Rc::downgrade(&state));