[librsvg: 13/17] XmlState: carry a LoadOptions instead of just its unlimited_size value




commit 20c95d4c9100a81773a19b3337e4e441d7f3b911
Author: Federico Mena Quintero <federico gnome org>
Date:   Mon Aug 29 20:23:09 2022 -0500

    XmlState: carry a LoadOptions instead of just its unlimited_size value
    
    Part-of: <https://gitlab.gnome.org/GNOME/librsvg/-/merge_requests/738>

 src/document.rs |  6 ++----
 src/xml/mod.rs  | 23 +++++++++++++++--------
 2 files changed, 17 insertions(+), 12 deletions(-)
---
diff --git a/src/document.rs b/src/document.rs
index 88281a4b0..190d6fa47 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 ad00710df..ac4529bc9 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));
 


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