samscott89 / serde_qs

Serde support for querystring-style strings
Apache License 2.0
194 stars 68 forks source link

Deserialization fails when sequence is first parameter at max_depth. #74

Open kevincox opened 1 year ago

kevincox commented 1 year ago

I was seeing a confusing error deserailizing a list. It was extra strange because this was working in other places in my code. It seems that there is a weird edge case when parsing a sequence at the max depth value (only tested with Vec and max_depth=1).

    #[derive(serde::Deserialize)]
    pub struct S {
        list: Vec<String>,
        other: bool,
    }

    serde_qs::Config::new(1, false).deserialize_str::<S>("other=true&list%5B%5D=foo").unwrap();
    serde_qs::Config::new(2, false).deserialize_str::<S>("list%5B%5D=foo&other=true").unwrap();
    serde_qs::Config::new(1, false).deserialize_str::<S>("list%5B%5D=foo&other=true").unwrap();

The first two work. My theory is that the first works because the list parameter isn't the first parameter and that the second one works because it has max_depth=2. However the third crashes with the following error:

thread 't' panicked at 'called Result::unwrap() on an Err value: Custom("invalid type: map, expected a sequence")', src/lib.rs:11:87