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

Failed parsing [ and ] in some cases #79

Open
chungwong opened this issue Mar 2, 2023 · 0 comments
Open

Failed parsing [ and ] in some cases #79

chungwong opened this issue Mar 2, 2023 · 0 comments

Comments

@chungwong
Copy link

It looks like the parser doesn't understand the qs if it contains nested keys like a[b][c]

use serde::{
    Deserialize,
    Serialize,
};

#[derive(Debug, Deserialize)]
struct Officer {
    first_name: String,
    last_name: String,
}

#[derive(Debug, Deserialize)]
struct Test {
    foo: String,
    officers: Vec<Officer>,
}

fn main() {
    let encoded = "foo=&officers%5B0%5D%5Bfirst_name%5D=&officers%5B0%5D%5Blast_name%5D=";
    dbg!(serde_qs::from_str::<Test>(encoded));

    let decoded = "foo=&officers[0][first_name]=&officers[0][last_name]=";
    dbg!(serde_qs::from_str::<Test>(decoded));
}

/// error output
[src/main.rs:20] serde_qs::from_str::<Test>(encoded) = Err(
    Custom(
        "missing field `officers`",
    ),
)

// successful output
[src/main.rs:24] serde_qs::from_str::<Test>(decoded) = Ok(
    Test {
        foo: "",
        officers: [
            Officer {
                first_name: "",
                last_name: "",
            },
        ],
    },
)
@chungwong chungwong changed the title Failed parsing [ and ]` in some cases Failed parsing [ and ] in some cases Mar 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant