Skip to content

xml serde roundtrip loses CR/LF encoding #670

Open
@francisdb

Description

@francisdb
use pretty_assertions::assert_eq;
use serde::{Deserialize, Serialize};

#[derive(Debug, Deserialize, Serialize)]
struct Root {
    #[serde(rename = "@value")]
    value: String,
}

const xml: &str = r#"<root value="new&#xD;&#xA;line"/>"#;

#[test]
fn test_attribute_value_normalization() {
    let read: Root = quick_xml::de::from_str(xml).unwrap();
    assert_eq!("new\r\nline", read.value);
    let written = quick_xml::se::to_string(&read).unwrap();
    assert_eq!(r#"<root value="new&#xD;&#xA;line"/>"#, written);
}

yields

thread 'test_attribute_value_normalization' panicked at tests/atest.rs:18:5:
assertion failed: `(left == right)`

Diff < left / right > :
<<root value="new&#xD;&#xA;line"/>
><Root value="new
>line"/>

Any workaround possible for the serializer?

Is this related to #115 ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    serdeIssues related to mapping from Rust types to XML

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions