From 09f64978102d7611050f033df9ffecd087509c02 Mon Sep 17 00:00:00 2001 From: Yuki Okushi Date: Thu, 29 Jan 2026 21:45:09 +0900 Subject: [PATCH] add tests --- actix-multipart/CHANGES.md | 2 ++ actix-multipart/src/form/mod.rs | 34 +++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/actix-multipart/CHANGES.md b/actix-multipart/CHANGES.md index 206374bf0..727cb897f 100644 --- a/actix-multipart/CHANGES.md +++ b/actix-multipart/CHANGES.md @@ -3,6 +3,7 @@ ## Unreleased - Minimum supported Rust version (MSRV) is now 1.83. +- Add `MultipartForm` support for `Option>` fields. [#3577] ## 0.7.2 @@ -82,6 +83,7 @@ - `MultipartError` is now marked as non-exhaustive. [#2451] [#2451]: https://github.com/actix/actix-web/pull/2451 +[#3577]: https://github.com/actix/actix-web/pull/3577 ## 0.4.0-beta.7 diff --git a/actix-multipart/src/form/mod.rs b/actix-multipart/src/form/mod.rs index e596573c7..cb89b7cc1 100644 --- a/actix-multipart/src/form/mod.rs +++ b/actix-multipart/src/form/mod.rs @@ -545,6 +545,40 @@ mod tests { assert_eq!(response.status(), StatusCode::OK); } + /// Test `Option` fields. + #[derive(MultipartForm)] + struct TestOptionVec { + list1: Option>>, + list2: Option>>, + } + + async fn test_option_vec_route(form: MultipartForm) -> impl Responder { + let form = form.into_inner(); + let strings = form + .list1 + .unwrap() + .into_iter() + .map(|s| s.into_inner()) + .collect::>(); + assert_eq!(strings, vec!["value1", "value2", "value3"]); + assert!(form.list2.is_none()); + HttpResponse::Ok().finish() + } + + #[actix_rt::test] + async fn test_option_vec() { + let srv = + actix_test::start(|| App::new().route("/", web::post().to(test_option_vec_route))); + + let mut form = multipart::Form::default(); + form.add_text("list1", "value1"); + form.add_text("list1", "value2"); + form.add_text("list1", "value3"); + + let response = send_form(&srv, form, "/").await; + assert_eq!(response.status(), StatusCode::OK); + } + /// Test the `rename` field attribute. #[derive(MultipartForm)] struct TestFieldRenaming {