Skip to content

Commit 3342375

Browse files
committed
Add ability to set entity resolver when deserialize using borrowing reader
1 parent 14db823 commit 3342375

File tree

2 files changed

+29
-8
lines changed

2 files changed

+29
-8
lines changed

Changelog.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,15 @@
1414

1515
- [#609]: Added `Writer::write_serializable` to provide the capability to serialize
1616
arbitrary types using serde when using the lower-level `Writer` API.
17+
- [#615]: Added ability to set entity resolver when deserialize using borrowing reader.
1718

1819
### Bug Fixes
1920

2021
### Misc Changes
2122

2223

2324
[#609]: https://github.com/tafia/quick-xml/issues/609
25+
[#615]: https://github.com/tafia/quick-xml/pull/615
2426

2527

2628
## 0.29.0 -- 2023-06-13

src/de/mod.rs

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2648,9 +2648,22 @@ where
26482648
}
26492649

26502650
impl<'de> Deserializer<'de, SliceReader<'de>> {
2651-
/// 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.
26522654
#[allow(clippy::should_implement_trait)]
26532655
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 {
26542667
let mut reader = Reader::from_str(source);
26552668
reader.expand_empty_elements(true);
26562669

@@ -2659,7 +2672,7 @@ impl<'de> Deserializer<'de, SliceReader<'de>> {
26592672
reader,
26602673
start_trimmer: StartTrimmer::default(),
26612674
},
2662-
NoEntityResolver,
2675+
entity_resolver,
26632676
)
26642677
}
26652678
}
@@ -2669,9 +2682,13 @@ where
26692682
R: BufRead,
26702683
{
26712684
/// Create new deserializer that will copy data from the specified reader
2672-
/// into internal buffer. If you already have a string use [`Self::from_str`]
2673-
/// instead, because it will borrow instead of copy. If you have `&[u8]` which
2674-
/// 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.
26752692
pub fn from_reader(reader: R) -> Self {
26762693
Self::with_resolver(reader, NoEntityResolver)
26772694
}
@@ -2683,9 +2700,11 @@ where
26832700
E: EntityResolver,
26842701
{
26852702
/// Create new deserializer that will copy data from the specified reader
2686-
/// into internal buffer. If you already have a string use [`Self::from_str`]
2687-
/// instead, because it will borrow instead of copy. If you have `&[u8]` which
2688-
/// 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`].
26892708
pub fn with_resolver(reader: R, entity_resolver: E) -> Self {
26902709
let mut reader = Reader::from_reader(reader);
26912710
reader.expand_empty_elements(true);

0 commit comments

Comments
 (0)