|
1 | | -use quick_xml::de::Deserializer; |
2 | 1 | use quick_xml::utils::{ByteBuf, Bytes}; |
3 | 2 | use quick_xml::DeError; |
4 | 3 |
|
@@ -1827,86 +1826,6 @@ mod borrow { |
1827 | 1826 | } |
1828 | 1827 | } |
1829 | 1828 |
|
1830 | | -/// Test for entity resolver |
1831 | | -mod resolve { |
1832 | | - use super::*; |
1833 | | - use pretty_assertions::assert_eq; |
1834 | | - use quick_xml::events::BytesText; |
1835 | | - use quick_xml::reader::{EntityResolver, EntityResolverFactory, ReplacementText}; |
1836 | | - use std::borrow::Cow; |
1837 | | - use std::collections::BTreeMap; |
1838 | | - use std::convert::Infallible; |
1839 | | - use std::iter::FromIterator; |
1840 | | - |
1841 | | - #[derive(Clone, Copy)] |
1842 | | - struct TestEntityResolver { |
1843 | | - capture_called: bool, |
1844 | | - } |
1845 | | - |
1846 | | - impl<'i> EntityResolverFactory<'i> for TestEntityResolver { |
1847 | | - type CaptureError = Infallible; |
1848 | | - type Resolver = Self; |
1849 | | - |
1850 | | - fn new_resolver(&mut self) -> Self::Resolver { |
1851 | | - *self |
1852 | | - } |
1853 | | - } |
1854 | | - |
1855 | | - impl<'i> EntityResolver<'i> for TestEntityResolver { |
1856 | | - type CaptureError = Infallible; |
1857 | | - |
1858 | | - fn capture(&mut self, doctype: BytesText) -> Result<(), Self::CaptureError> { |
1859 | | - self.capture_called = true; |
1860 | | - |
1861 | | - assert_eq!(doctype.as_ref(), br#"dict[ <!ENTITY unc "unclassified"> ]"#); |
1862 | | - |
1863 | | - Ok(()) |
1864 | | - } |
1865 | | - |
1866 | | - fn resolve<'e>(&self, entity: &str) -> Option<ReplacementText<'i, 'e>> { |
1867 | | - assert!( |
1868 | | - self.capture_called, |
1869 | | - "`EntityResolver::capture` should be called before `EntityResolver::resolve`" |
1870 | | - ); |
1871 | | - match entity { |
1872 | | - "t1" => Some(ReplacementText::Internal(Cow::Borrowed(b"test_one"))), |
1873 | | - "t2" => Some(ReplacementText::Internal(Cow::Borrowed(b"test_two"))), |
1874 | | - _ => None, |
1875 | | - } |
1876 | | - } |
1877 | | - } |
1878 | | - |
1879 | | - #[test] |
1880 | | - fn resolve_custom_entity() { |
1881 | | - let resolver = TestEntityResolver { |
1882 | | - capture_called: false, |
1883 | | - }; |
1884 | | - let mut de = Deserializer::with_resolver( |
1885 | | - br#" |
1886 | | - <!DOCTYPE dict[ <!ENTITY unc "unclassified"> ]> |
1887 | | -
|
1888 | | - <root> |
1889 | | - <entity_one>&t1;</entity_one> |
1890 | | - <entity_two>&t2;</entity_two> |
1891 | | - <entity_three>non-entity</entity_three> |
1892 | | - </root> |
1893 | | - "# |
1894 | | - .as_ref(), |
1895 | | - resolver, |
1896 | | - ); |
1897 | | - |
1898 | | - let data: BTreeMap<String, String> = BTreeMap::deserialize(&mut de).unwrap(); |
1899 | | - assert_eq!( |
1900 | | - data, |
1901 | | - BTreeMap::from_iter([ |
1902 | | - (String::from("entity_one"), String::from("test_one")), |
1903 | | - (String::from("entity_two"), String::from("test_two")), |
1904 | | - (String::from("entity_three"), String::from("non-entity")), |
1905 | | - ]) |
1906 | | - ); |
1907 | | - } |
1908 | | -} |
1909 | | - |
1910 | 1829 | /// Tests for https://github.com/tafia/quick-xml/pull/603. |
1911 | 1830 | /// |
1912 | 1831 | /// According to <https://www.w3.org/TR/xml11/#NT-prolog> comments, |
|
0 commit comments