@@ -1813,14 +1813,6 @@ macro_rules! deserialize_primitives {
1813
1813
str2bool( & text, visitor)
1814
1814
}
1815
1815
1816
- /// Representation of owned strings the same as [non-owned](#method.deserialize_str).
1817
- fn deserialize_string<V >( self , visitor: V ) -> Result <V :: Value , DeError >
1818
- where
1819
- V : Visitor <' de>,
1820
- {
1821
- self . deserialize_str( visitor)
1822
- }
1823
-
1824
1816
/// Character represented as [strings](#method.deserialize_str).
1825
1817
fn deserialize_char<V >( self , visitor: V ) -> Result <V :: Value , DeError >
1826
1818
where
@@ -1840,6 +1832,14 @@ macro_rules! deserialize_primitives {
1840
1832
}
1841
1833
}
1842
1834
1835
+ /// Representation of owned strings the same as [non-owned](#method.deserialize_str).
1836
+ fn deserialize_string<V >( self , visitor: V ) -> Result <V :: Value , DeError >
1837
+ where
1838
+ V : Visitor <' de>,
1839
+ {
1840
+ self . deserialize_str( visitor)
1841
+ }
1842
+
1843
1843
/// Returns [`DeError::Unsupported`]
1844
1844
fn deserialize_bytes<V >( self , _visitor: V ) -> Result <V :: Value , DeError >
1845
1845
where
@@ -1856,7 +1856,7 @@ macro_rules! deserialize_primitives {
1856
1856
self . deserialize_bytes( visitor)
1857
1857
}
1858
1858
1859
- /// Representation of the named units the same as [unnamed units](#method.deserialize_unit)
1859
+ /// Representation of the named units the same as [unnamed units](#method.deserialize_unit).
1860
1860
fn deserialize_unit_struct<V >(
1861
1861
self ,
1862
1862
_name: & ' static str ,
@@ -1868,6 +1868,7 @@ macro_rules! deserialize_primitives {
1868
1868
self . deserialize_unit( visitor)
1869
1869
}
1870
1870
1871
+ /// Representation of the newtypes the same as one-element [tuple](#method.deserialize_tuple).
1871
1872
fn deserialize_newtype_struct<V >(
1872
1873
self ,
1873
1874
_name: & ' static str ,
@@ -2068,14 +2069,7 @@ struct XmlReader<'i, R: XmlRead<'i>, E: EntityResolver = NoEntityResolver> {
2068
2069
}
2069
2070
2070
2071
impl < ' i , R : XmlRead < ' i > , E : EntityResolver > XmlReader < ' i , R , E > {
2071
- fn new ( reader : R ) -> Self
2072
- where
2073
- E : Default ,
2074
- {
2075
- Self :: with_resolver ( reader, E :: default ( ) )
2076
- }
2077
-
2078
- fn with_resolver ( mut reader : R , entity_resolver : E ) -> Self {
2072
+ fn new ( mut reader : R , entity_resolver : E ) -> Self {
2079
2073
// Lookahead by one event immediately, so we do not need to check in the
2080
2074
// loop if we need lookahead or not
2081
2075
let lookahead = reader. next ( ) ;
@@ -2319,19 +2313,20 @@ where
2319
2313
peek : Option < DeEvent < ' de > > ,
2320
2314
}
2321
2315
2322
- impl < ' de , R > Deserializer < ' de , R >
2316
+ impl < ' de , R , E > Deserializer < ' de , R , E >
2323
2317
where
2324
2318
R : XmlRead < ' de > ,
2319
+ E : EntityResolver ,
2325
2320
{
2326
2321
/// Create an XML deserializer from one of the possible quick_xml input sources.
2327
2322
///
2328
2323
/// Typically it is more convenient to use one of these methods instead:
2329
2324
///
2330
2325
/// - [`Deserializer::from_str`]
2331
2326
/// - [`Deserializer::from_reader`]
2332
- fn new ( reader : R ) -> Self {
2327
+ fn new ( reader : R , entity_resolver : E ) -> Self {
2333
2328
Self {
2334
- reader : XmlReader :: new ( reader) ,
2329
+ reader : XmlReader :: new ( reader, entity_resolver ) ,
2335
2330
2336
2331
#[ cfg( feature = "overlapped-lists" ) ]
2337
2332
read : VecDeque :: new ( ) ,
@@ -2344,13 +2339,7 @@ where
2344
2339
peek : None ,
2345
2340
}
2346
2341
}
2347
- }
2348
2342
2349
- impl < ' de , R , E > Deserializer < ' de , R , E >
2350
- where
2351
- R : XmlRead < ' de > ,
2352
- E : EntityResolver ,
2353
- {
2354
2343
/// Set the maximum number of events that could be skipped during deserialization
2355
2344
/// of sequences.
2356
2345
///
@@ -2659,15 +2648,32 @@ where
2659
2648
}
2660
2649
2661
2650
impl < ' de > Deserializer < ' de , SliceReader < ' de > > {
2662
- /// Create new deserializer that will borrow data from the specified string
2651
+ /// Create new deserializer that will borrow data from the specified string.
2652
+ ///
2653
+ /// Deserializer created with this method will not resolve custom entities.
2663
2654
#[ allow( clippy:: should_implement_trait) ]
2664
- pub fn from_str ( s : & ' de str ) -> Self {
2665
- let mut reader = Reader :: from_str ( s) ;
2666
- reader. expand_empty_elements ( true ) . check_end_names ( true ) ;
2667
- Self :: new ( SliceReader {
2668
- reader,
2669
- start_trimmer : StartTrimmer :: default ( ) ,
2670
- } )
2655
+ pub fn from_str ( source : & ' de str ) -> Self {
2656
+ Self :: from_str_with_resolver ( source, NoEntityResolver )
2657
+ }
2658
+ }
2659
+
2660
+ impl < ' de , E > Deserializer < ' de , SliceReader < ' de > , E >
2661
+ where
2662
+ E : EntityResolver ,
2663
+ {
2664
+ /// Create new deserializer that will borrow data from the specified string
2665
+ /// and use specified entity resolver.
2666
+ pub fn from_str_with_resolver ( source : & ' de str , entity_resolver : E ) -> Self {
2667
+ let mut reader = Reader :: from_str ( source) ;
2668
+ reader. expand_empty_elements ( true ) ;
2669
+
2670
+ Self :: new (
2671
+ SliceReader {
2672
+ reader,
2673
+ start_trimmer : StartTrimmer :: default ( ) ,
2674
+ } ,
2675
+ entity_resolver,
2676
+ )
2671
2677
}
2672
2678
}
2673
2679
@@ -2676,9 +2682,13 @@ where
2676
2682
R : BufRead ,
2677
2683
{
2678
2684
/// Create new deserializer that will copy data from the specified reader
2679
- /// into internal buffer. If you already have a string use [`Self::from_str`]
2680
- /// instead, because it will borrow instead of copy. If you have `&[u8]` which
2681
- /// is known to represent UTF-8, you can decode it first before using [`from_str`].
2685
+ /// into internal buffer.
2686
+ ///
2687
+ /// If you already have a string use [`Self::from_str`] instead, because it
2688
+ /// will borrow instead of copy. If you have `&[u8]` which is known to represent
2689
+ /// UTF-8, you can decode it first before using [`from_str`].
2690
+ ///
2691
+ /// Deserializer created with this method will not resolve custom entities.
2682
2692
pub fn from_reader ( reader : R ) -> Self {
2683
2693
Self :: with_resolver ( reader, NoEntityResolver )
2684
2694
}
@@ -2690,32 +2700,23 @@ where
2690
2700
E : EntityResolver ,
2691
2701
{
2692
2702
/// Create new deserializer that will copy data from the specified reader
2693
- /// into internal buffer. If you already have a string use [`Self::from_str`]
2694
- /// instead, because it will borrow instead of copy. If you have `&[u8]` which
2695
- /// is known to represent UTF-8, you can decode it first before using [`from_str`].
2703
+ /// into internal buffer and use specified entity resolver.
2704
+ ///
2705
+ /// If you already have a string use [`Self::from_str`] instead, because it
2706
+ /// will borrow instead of copy. If you have `&[u8]` which is known to represent
2707
+ /// UTF-8, you can decode it first before using [`from_str`].
2696
2708
pub fn with_resolver ( reader : R , entity_resolver : E ) -> Self {
2697
2709
let mut reader = Reader :: from_reader ( reader) ;
2698
- reader. expand_empty_elements ( true ) . check_end_names ( true ) ;
2699
-
2700
- let io_reader = IoReader {
2701
- reader,
2702
- start_trimmer : StartTrimmer :: default ( ) ,
2703
- buf : Vec :: new ( ) ,
2704
- } ;
2705
-
2706
- Self {
2707
- reader : XmlReader :: with_resolver ( io_reader, entity_resolver) ,
2708
-
2709
- #[ cfg( feature = "overlapped-lists" ) ]
2710
- read : VecDeque :: new ( ) ,
2711
- #[ cfg( feature = "overlapped-lists" ) ]
2712
- write : VecDeque :: new ( ) ,
2713
- #[ cfg( feature = "overlapped-lists" ) ]
2714
- limit : None ,
2710
+ reader. expand_empty_elements ( true ) ;
2715
2711
2716
- #[ cfg( not( feature = "overlapped-lists" ) ) ]
2717
- peek : None ,
2718
- }
2712
+ Self :: new (
2713
+ IoReader {
2714
+ reader,
2715
+ start_trimmer : StartTrimmer :: default ( ) ,
2716
+ buf : Vec :: new ( ) ,
2717
+ } ,
2718
+ entity_resolver,
2719
+ )
2719
2720
}
2720
2721
}
2721
2722
@@ -3606,10 +3607,7 @@ mod tests {
3606
3607
start_trimmer : StartTrimmer :: default ( ) ,
3607
3608
} ;
3608
3609
3609
- reader
3610
- . reader
3611
- . expand_empty_elements ( true )
3612
- . check_end_names ( true ) ;
3610
+ reader. reader . expand_empty_elements ( true ) ;
3613
3611
3614
3612
let mut events = Vec :: new ( ) ;
3615
3613
0 commit comments