Skip to content
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

Deserialize does not handle escape backslash #1240

Closed
TAYTS opened this issue Feb 14, 2025 · 1 comment
Closed

Deserialize does not handle escape backslash #1240

TAYTS opened this issue Feb 14, 2025 · 1 comment

Comments

@TAYTS
Copy link

TAYTS commented Feb 14, 2025

Hi I am not sure if this is intended but when deserialize from JSON string, escaped \ does not seems to unescape.

use serde::Deserialize;

#[derive(Deserialize)]
struct Data {
    data: String,
}

fn main() {
    let raw_data = r#"{"data":"test\\.data"}"#;
    let data = serde_json::from_str::<Data>(raw_data).unwrap();
    println!(">>>data: {:?}", data.data); // return "test\\.data" instead of "test\.data"
}

Rust playground: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=72e2e0e83410f7a5977287a58c247eca

@dtolnay
Copy link
Member

dtolnay commented Feb 14, 2025

I am confident this is handled correctly.

That output is what it looks like when a String contains one backslash.

@dtolnay dtolnay closed this as completed Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants