Skip to content

Commit 43e0d28

Browse files
authored
Empty req_body_form() should set body to an empty list (#836)
Fixes #835
1 parent 6867108 commit 43e0d28

3 files changed

Lines changed: 10 additions & 1 deletion

File tree

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* `oauth_flow_auth_code()` now correctly uses the same redirect URI for both authorization and token requests when using the default localhost redirect URL (@pedrobtz, #829).
44
* `last_response_json()` now works with content-types that end with `+json`,
55
e.g., `application/problem+json` (@cgiachalis, #782).
6+
* `req_body_form()` now creates a valid empty request body when no parameters
7+
are provided (@arcresu, #836).
68

79
# httr2 1.2.2
810

R/req-body.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ req_body_form <- function(
156156
check_request(.req)
157157

158158
dots <- multi_dots(..., .multi = .multi)
159-
data <- modify_list(.req$body$data, !!!dots)
159+
data <- modify_list(.req$body$data %||% list(), !!!dots)
160160
req_body(.req, data = data, type = "form")
161161
}
162162

tests/testthat/test-req-body.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,6 +197,13 @@ test_that("form data is unobufcated", {
197197
expect_equal(rawToChar(req$options$postfields), 'x=x&y=y')
198198
})
199199

200+
test_that("empty form data gives a valid request", {
201+
req <- request_test() |>
202+
req_body_form() |>
203+
req_body_apply()
204+
expect_equal(req$body$data, list())
205+
})
206+
200207
# req_body_multipart() ---------------------------------------------------------
201208

202209
test_that("can send named elements as multipart", {

0 commit comments

Comments
 (0)