Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# httr2 (development version)

* Refactor `url_modify()` to better retain exact formatting of URL components
that are not modified. (#788)
that are not modified. (#788, #794)

# httr2 1.2.1

Expand Down
8 changes: 4 additions & 4 deletions R/req-url.R
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,10 @@ req_url_path_append <- function(req, ...) {
check_request(req)
path <- dots_to_path(...)

url <- url_parse(req$url)
url$path <- paste0(sub("/$", "", url$path), path)

req_url(req, url_build(url))
# Keep verbatim url-encoding of input path
input <- curl::curl_parse_url(req$url, decode = FALSE)$path
path <- paste0(sub("/$", "", input), path)
req_url(req, curl::curl_modify_url(req$url, path = I(path)))
}

#' Get request URL
Expand Down
12 changes: 12 additions & 0 deletions tests/testthat/test-url.R
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,18 @@ test_that("only modifies specified components", {
expect_equal(url_modify(url, query = list(x=1)), "http://x.com/a%2Fb/?x=1")
})

test_that("appending to path does not normalise encoding", {
req <- request("http://x.com/a%2Fb/")
expect_equal(
req_url_path_append(req, "foo/bar")$url,
"http://x.com/a%2Fb/foo/bar"
)
expect_equal(
req_url_path_append(req, "foo%2Fbar")$url,
"http://x.com/a%2Fb/foo%2Fbar"
)
})

# relative url ------------------------------------------------------------

test_that("can set relative urls", {
Expand Down
Loading