diff --git a/NEWS.md b/NEWS.md index 233d4bfb..36646dd5 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # httr2 (development version) +* `req_url_query()` now re-calculates n lengths when using `.multi = "explode"` to avoid select/recycling issues (@Kevanness, #719). + # httr2 1.1.2 * `req_headers()` more carefully checks its input types (#707). diff --git a/R/utils-multi.R b/R/utils-multi.R index 2e1b2b78..4ffb1b58 100644 --- a/R/utils-multi.R +++ b/R/utils-multi.R @@ -64,13 +64,7 @@ multi_dots <- function( dots[n > 1] <- lapply(dots[n > 1], I) } else if (.multi == "explode") { dots <- explode(dots) - dots[n > 1] <- imap( - dots[n > 1], - format_query_param, - multi = TRUE, - form = form - ) - dots[n > 1] <- lapply(dots[n > 1], I) + n <- lengths(dots) } else if (.multi == "error") { cli::cli_abort( c( diff --git a/tests/testthat/test-utils-multi.R b/tests/testthat/test-utils-multi.R index b5c89707..7613d139 100644 --- a/tests/testthat/test-utils-multi.R +++ b/tests/testthat/test-utils-multi.R @@ -17,6 +17,25 @@ test_that("can handle multi query params", { ) }) +test_that("can handle mixed length multi query params", { + expect_equal( + multi_dots(a = 1:2, b = 1, c = NULL, .multi = "explode"), + list(a = I("1"), a = I("2"), b = I("1"), c = NULL) + ) + expect_equal( + multi_dots(a = 1:2, b = 1, c = NULL, .multi = "comma"), + list(a = I("1,2"), b = I("1"), c = NULL) + ) + expect_equal( + multi_dots(a = 1:2, b = 1, c = NULL, .multi = "pipe"), + list(a = I("1|2"), b = I("1"), c = NULL) + ) + expect_equal( + multi_dots(a = 1:2, b = 1, c = NULL, .multi = function(x) "X"), + list(a = I("X"), b = I("1"), c = NULL) + ) +}) + test_that("can opt-out of escaping for' vectors", { expect_equal( multi_dots(a = I(c(" ", " ")), .multi = "comma"),