jplatte / serde_html_form

Rust crate for (de-)serialization of `application/x-www-form-urlencoded` data.
MIT License
23 stars 3 forks source link

Change behavior for empty values when deserializing an option #13

Open jplatte opened 9 months ago

jplatte commented 9 months ago

Currently, the following two forms get the foo field deserialized to None given the input foo=:

#[derive(Deserialize)]
struct FormA {
    foo: Option<String>,
}

#[derive(Deserialize)]
struct FormB {
   foo: Option<Vec<String>>,
}

I think the most reasonable output would instead be an empty string (as the only list element) wrapped in Some for both forms.

What might also be relevant: I think the same forms with String replaced by f64 should produce foo: None for FormA and a deserialization error for FormB. I think both should already be the case.

This is a breaking change, so if implemented I will publish it as part of serde_html_form 0.3.0.

jplatte commented 1 month ago

Should also when working on this consider testing ?foo separately from ?foo=. Both should produce an empty string (see discussion in #21).