diff --git a/instant-xml/src/impls.rs b/instant-xml/src/impls.rs index da144dd..c5b97fc 100644 --- a/instant-xml/src/impls.rs +++ b/instant-xml/src/impls.rs @@ -529,7 +529,7 @@ impl ToXml for Option { fn encode(input: &str) -> Result, Error> { let mut result = String::with_capacity(input.len()); let mut last_end = 0; - for (start, c) in input.chars().enumerate() { + for (start, c) in input.char_indices() { let to = match c { '&' => "&", '"' => """, @@ -849,7 +849,7 @@ impl<'xml> FromXml<'xml> for IpAddr { #[cfg(test)] mod tests { - use super::decode; + use super::*; #[test] fn test_decode() { @@ -867,4 +867,10 @@ mod tests { assert!(decode("&foobar;").is_err()); assert!(decode("cbdtéd&ü").is_err()); } + + #[test] + fn encode_unicode() { + let input = "Iñtërnâ&tiônàlizætiøn"; + assert_eq!(encode(input).unwrap(), "Iñtërnâ&tiônàlizætiøn"); + } }