Correctly handle multi-byte characters in string encoding
This commit is contained in:
parent
8be61f6017
commit
82ca8a224e
|
@ -529,7 +529,7 @@ impl<T: ToXml> ToXml for Option<T> {
|
|||
fn encode(input: &str) -> Result<Cow<'_, str>, 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");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue