-
Notifications
You must be signed in to change notification settings - Fork 246
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
from_str adds extra backslashs #321
Comments
Can you provide an example? |
Sure... Dependencies [dependencies]
serde = { version = "1.0", features = [ "derive" ] }
quick-xml = { version = "0.21", features = [ "serialize" ] }
csv = "1.1.6" Code extern crate quick_xml;
use quick_xml::de::from_str;
use serde::Deserialize;
#[derive(Debug, Deserialize)]
struct Secret {
#[serde(rename = "SecretName")]
secret_name: String,
#[serde(rename = "FolderPath")]
folder_path: String,
}
fn main() {
let xml = r#"<Secret>
<SecretName>VerySecret</SecretName>
<FolderPath>\Infrastructure\Network</FolderPath>
</Secret>"#;
let result: Secret = from_str(&xml).unwrap();
println!("{:#?}", result);
} Result Secret {
secret_name: "VerySecret",
folder_path: "\\Infrastructure\\Network",
} Expected Secret {
secret_name: "VerySecret",
folder_path: "\Infrastructure\Network",
} |
That may be a quirk of debug display and the actual string has one backslash. For example, run the following code: #[derive(Debug)]
struct Object {
name: String
}
fn main() {
let obj = Object {name: r"\".to_string()};
println!("{:#?}", obj);
} output:
|
I didn't see it, this definitely seems the case. Could you try comparing the actual result with |
Is this also related to escaping happening in attribute values (which must AFAIK be quoted anyway)? e.g.: <CONSTRAINT
DESCRIPTION="Time alignable annotations within the parent annotation's time interval, gaps are allowed"
STEREOTYPE="Included_In"/> The above deserialised then serialised (apostrophe in <CONSTRAINT
DESCRIPTION="Time alignable annotations within the parent annotation's time interval, gaps are allowed"
STEREOTYPE="Included_In"/> Expected behaviour would be for this to happen only for (unquoted) element values/text, not attributes. The serialised xml in question does validate in either case however. |
The double slash in the output is the result of using The quoting in the XML attributes is excessive and can be avoided, because standard allows to not escape apostrophe if attribute value in double quotes |
Duplicate of #362 |
When deserializing from XML to a struct, quick-xml adds an extra backslash to backslashes, like its trying to escape them.
So
<FolderPath>\Infrastructure\Network</FolderPath>
becomesfolder_path: "\\Infrastructure\\Network"
.Is that a bug or am I missing something ?
The text was updated successfully, but these errors were encountered: