diff --git a/src/de/map.rs b/src/de/map.rs index 325a4b7b..20d7c10f 100644 --- a/src/de/map.rs +++ b/src/de/map.rs @@ -245,14 +245,14 @@ where // that value should be taken from the text content of the // XML node seed.deserialize(VALUE_KEY.into_deserializer()).map(Some) - }, + } DeEvent::Text(_) | DeEvent::CData(_) => { self.source = ValueSource::Text; // Deserialize `key` from special attribute name which means // that value should be taken from the text content of the // XML node seed.deserialize(TEXT_KEY.into_deserializer()).map(Some) - }, + } // Used to deserialize collections of enums, like: // // @@ -272,13 +272,13 @@ where DeEvent::Start(e) if self.has_value_field && not_in(self.fields, e, decoder)? => { self.source = ValueSource::Content; seed.deserialize(VALUE_KEY.into_deserializer()).map(Some) - }, + } DeEvent::Start(e) => { self.source = ValueSource::Nested; let de = QNameDeserializer::from_elem(e.name(), decoder)?; seed.deserialize(de).map(Some) - }, + } // Stop iteration after reaching a closing tag DeEvent::End(e) if e.name() == self.start.name() => Ok(None), // This is a unmatched closing tag, so the XML is invalid @@ -701,7 +701,7 @@ where DeEvent::Start(e) if !self.filter.is_suitable(e, decoder)? => { self.map.de.skip()?; continue; - }, + } // Stop iteration when list elements ends #[cfg(not(feature = "overlapped-lists"))] DeEvent::Start(e) if !self.filter.is_suitable(e, decoder)? => Ok(None), @@ -847,7 +847,7 @@ where // TODO: May be assert that here we expect only matching closing tag? self.map.de.read_to_end(e.name())?; value - }, + } // SAFETY: we use that deserializer only when Start(element), Text, // or CData event Start(tag), Text, CData was peeked already _ => unreachable!(), diff --git a/src/events/attributes.rs b/src/events/attributes.rs index e2d1278f..c25f2c85 100644 --- a/src/events/attributes.rs +++ b/src/events/attributes.rs @@ -632,16 +632,11 @@ impl<'a> IterState<'a> { Some((_, b'\'')) => b'\'', Some((offset, &q)) => { - if let Some(q) = self - .custom_quotes - .iter() - .find(|(o, _)| *o == q) - .map(|(_, c)| *c) - { + if let Some((_, c)) = self.custom_quotes.iter().find(|(o, _)| *o == q) { // Input: ` key = q` // | ^ // offset - q + *c } else { // Input: ` key = x` // | ^ @@ -1057,6 +1052,26 @@ mod xml { assert_eq!(iter.next(), None); } + #[test] + fn double_squoted() { + let mut iter = Attributes::new_with_custom_quotes( + r#"tag key=`value()=>} other=`(e) => {}}"#, + 3, + &[(b'`', b'}')], + ); + + assert_eq!( + iter.next(), + Some(Ok(Attribute { + key: QName(b"key"), + value: Cow::Borrowed(b"value()=>"), + quote: Attr::CustomQ(b'`', b'}', (), ()) + })) + ); + assert_eq!(iter.next(), None); + assert_eq!(iter.next(), None); + } + /// Attribute have a value enclosed in double quotes #[test] fn double_quoted() { @@ -1082,6 +1097,35 @@ mod xml { assert_eq!(iter.next(), None); } + /// Attribute have a value enclosed in custom quotes + #[test] + fn custom_quoted() { + let mut iter = Attributes::new_with_custom_quotes( + r#"tag key=`value` regular='attribute'"#, + 3, + &[(b'`', b'`')], + ); + + assert_eq!( + iter.next(), + Some(Ok(Attribute { + key: QName(b"key"), + value: Cow::Borrowed(b"value"), + quote: Attr::CustomQ(b'`', b'`', (), ()) + })) + ); + assert_eq!( + iter.next(), + Some(Ok(Attribute { + key: QName(b"regular"), + value: Cow::Borrowed(b"attribute"), + quote: Attr::SingleQ((), ()) + })) + ); + assert_eq!(iter.next(), None); + assert_eq!(iter.next(), None); + } + /// Attribute have a value, not enclosed in quotes #[test] fn unquoted() { @@ -1271,6 +1315,24 @@ mod xml { assert_eq!(iter.next(), None); } + /// Attribute have a value, not enclosed in quotes + #[test] + fn custom_quoted() { + let mut iter = + Attributes::new_with_custom_quotes(r#"tag key = `value` "#, 3, &[(b'`', b'`')]); + + assert_eq!( + iter.next(), + Some(Ok(Attribute { + key: QName(b"key"), + value: Cow::Borrowed(b"value"), + quote: Attr::CustomQ(b'`', b'`', (), ()) + })) + ); + assert_eq!(iter.next(), None); + assert_eq!(iter.next(), None); + } + /// Attribute have a value, not enclosed in quotes #[test] fn unquoted() { diff --git a/src/name.rs b/src/name.rs index 393640a7..2f09733b 100644 --- a/src/name.rs +++ b/src/name.rs @@ -302,7 +302,7 @@ impl<'ns> Debug for ResolveResult<'ns> { write!(f, "Unknown(")?; write_byte_string(f, p)?; write!(f, ")") - }, + } } } } @@ -424,7 +424,7 @@ impl NamespaceResolver { value_len: v.len(), level, }); - }, + } Some(PrefixDeclaration::Named(prefix)) => { let start = buffer.len(); buffer.extend_from_slice(prefix); @@ -435,8 +435,8 @@ impl NamespaceResolver { value_len: v.len(), level, }); - }, - None => {}, + } + None => {} } } else { break; @@ -457,14 +457,14 @@ impl NamespaceResolver { None => { buffer.clear(); self.bindings.clear(); - }, + } // drop all namespaces past the last valid namespace Some(last_valid_pos) => { if let Some(len) = self.bindings.get(last_valid_pos + 1).map(|n| n.start) { buffer.truncate(len); self.bindings.truncate(last_valid_pos + 1); } - }, + } } } diff --git a/src/reader/mod.rs b/src/reader/mod.rs index 1f5755ee..5eb60dbc 100644 --- a/src/reader/mod.rs +++ b/src/reader/mod.rs @@ -776,8 +776,8 @@ impl BangType { if i == 0 && buf.ends_with(b"--") { return Some((&[], i + 1)); // +1 for `>` } - }, - Self::Comment => {}, + } + Self::Comment => {} Self::CData => { if chunk[..i].ends_with(b"]]") { return Some((&chunk[..i], i + 1)); // +1 for `>` @@ -792,7 +792,7 @@ impl BangType { if i == 0 && buf.ends_with(b"]]") { return Some((&[], i + 1)); // +1 for `>` } - }, + } Self::DocType => { let content = &chunk[..i]; let balance = memchr::memchr2_iter(b'<', b'>', content) @@ -801,7 +801,7 @@ impl BangType { if balance == 0 { return Some((content, i + 1)); // +1 for `>` } - }, + } } } None @@ -854,7 +854,7 @@ impl ReadElementState { } else { *self } - }, + } // all other bytes: no state change _ => *self, diff --git a/src/reader/ns_reader.rs b/src/reader/ns_reader.rs index 078dc627..4ce816fa 100644 --- a/src/reader/ns_reader.rs +++ b/src/reader/ns_reader.rs @@ -76,20 +76,20 @@ impl NsReader { Ok(Event::Start(e)) => { self.ns_resolver.push(&e, &mut self.buffer); Ok(Event::Start(e)) - }, + } Ok(Event::Empty(e)) => { self.ns_resolver.push(&e, &mut self.buffer); // notify next `read_event_impl()` invocation that it needs to pop this // namespace scope self.pending_pop = true; Ok(Event::Empty(e)) - }, + } Ok(Event::End(e)) => { // notify next `read_event_impl()` invocation that it needs to pop this // namespace scope self.pending_pop = true; Ok(Event::End(e)) - }, + } e => e, } } diff --git a/tests/encodings.rs b/tests/encodings.rs index 08584ea2..fa721e93 100644 --- a/tests/encodings.rs +++ b/tests/encodings.rs @@ -36,7 +36,7 @@ fn test_koi8_r_encoding() { match r.read_event_into(&mut buf) { Ok(Event::Text(e)) => { e.unescape().unwrap(); - }, + } Ok(Event::Eof) => break, _ => (), } diff --git a/tests/namespaces.rs b/tests/namespaces.rs index e10a48fe..74d5a6ca 100644 --- a/tests/namespaces.rs +++ b/tests/namespaces.rs @@ -231,7 +231,7 @@ fn default_ns_shadowing_empty() { Ok((ns, Start(e))) => { assert_eq!(ns, Bound(Namespace(b"urn:example:o"))); assert_eq!(e.name(), QName(b"e")); - }, + } e => panic!("Expected Start event (), got {:?}", e), } } @@ -243,7 +243,7 @@ fn default_ns_shadowing_empty() { assert_eq!(ns, Bound(Namespace(b"urn:example:i"))); assert_eq!(e.name(), QName(b"e")); e - }, + } e => panic!("Expecting Empty event, got {:?}", e), }; @@ -274,7 +274,7 @@ fn default_ns_shadowing_empty() { Ok((ns, End(e))) => { assert_eq!(ns, Bound(Namespace(b"urn:example:o"))); assert_eq!(e.name(), QName(b"e")); - }, + } e => panic!("Expected End event (), got {:?}", e), } } @@ -292,7 +292,7 @@ fn default_ns_shadowing_expanded() { Ok((ns, Start(e))) => { assert_eq!(ns, Bound(Namespace(b"urn:example:o"))); assert_eq!(e.name(), QName(b"e")); - }, + } e => panic!("Expected Start event (), got {:?}", e), } } @@ -304,7 +304,7 @@ fn default_ns_shadowing_expanded() { assert_eq!(ns, Bound(Namespace(b"urn:example:i"))); assert_eq!(e.name(), QName(b"e")); e - }, + } e => panic!("Expecting Start event (), got {:?}", e), }; let mut attrs = e @@ -334,7 +334,7 @@ fn default_ns_shadowing_expanded() { Ok((ns, End(e))) => { assert_eq!(ns, Bound(Namespace(b"urn:example:i"))); assert_eq!(e.name(), QName(b"e")); - }, + } e => panic!("Expected End event (), got {:?}", e), } // @@ -342,7 +342,7 @@ fn default_ns_shadowing_expanded() { Ok((ns, End(e))) => { assert_eq!(ns, Bound(Namespace(b"urn:example:o"))); assert_eq!(e.name(), QName(b"e")); - }, + } e => panic!("Expected End event (), got {:?}", e), } } diff --git a/tests/test.rs b/tests/test.rs index 35e2f209..82c3089b 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -48,7 +48,7 @@ fn test_attributes_empty() { })) ); assert_eq!(attrs.next(), None); - }, + } e => panic!("Expecting Empty event, got {:?}", e), } } @@ -70,7 +70,7 @@ fn test_attribute_equal() { })) ); assert_eq!(attrs.next(), None); - }, + } e => panic!("Expecting Empty event, got {:?}", e), } } @@ -85,7 +85,7 @@ fn test_comment_starting_with_gt() { Ok(Comment(e)) => { assert_eq!(e.as_ref(), b">"); break; - }, + } Ok(Eof) => panic!("Expecting Comment"), _ => (), } @@ -181,7 +181,7 @@ fn test_issue299() -> Result<(), Error> { "mismatch att count on '{:?}'", reader.decoder().decode(e.name().as_ref()) ); - }, + } Eof => break, _ => (), } diff --git a/tests/unit_tests.rs b/tests/unit_tests.rs index e5e21600..dca106b5 100644 --- a/tests/unit_tests.rs +++ b/tests/unit_tests.rs @@ -152,7 +152,7 @@ fn test_xml_decl() { None => (), e => panic!("doesn't expect standalone, got {:?}", e), } - }, + } _ => panic!("unable to parse XmlDecl"), } } @@ -309,7 +309,7 @@ fn test_write_attrs() -> Result<()> { elem.extend_attributes(attrs); elem.push_attribute(("x", "y\"z")); Start(elem) - }, + } End(_) => End(BytesEnd::new("copy")), e => e, }; @@ -500,7 +500,7 @@ fn test_escaped_content() { e ), } - }, + } Ok(e) => panic!("Expecting text event, got {:?}", e), Err(e) => panic!( "Cannot get next event at position {}: {:?}", @@ -583,7 +583,7 @@ fn test_read_write_roundtrip_escape_text() -> Result<()> { Text(e) => { let t = e.unescape().unwrap(); assert!(writer.write_event(Text(BytesText::new(&t))).is_ok()); - }, + } e => assert!(writer.write_event(e).is_ok()), } } @@ -617,7 +617,7 @@ fn test_closing_bracket_in_single_quote_attr() { })) ); assert_eq!(attrs.next(), None); - }, + } x => panic!("expected , got {:?}", x), } next_eq!(r, End, b"a"); @@ -647,7 +647,7 @@ fn test_closing_bracket_in_double_quote_attr() { })) ); assert_eq!(attrs.next(), None); - }, + } x => panic!("expected , got {:?}", x), } next_eq!(r, End, b"a"); @@ -677,7 +677,7 @@ fn test_closing_bracket_in_double_quote_mixed() { })) ); assert_eq!(attrs.next(), None); - }, + } x => panic!("expected , got {:?}", x), } next_eq!(r, End, b"a"); @@ -707,7 +707,7 @@ fn test_closing_bracket_in_single_quote_mixed() { })) ); assert_eq!(attrs.next(), None); - }, + } x => panic!("expected , got {:?}", x), } next_eq!(r, End, b"a");