diff --git a/NEWS.md b/NEWS.md index b00aa291..c0dfa0ef 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # httr2 (development version) +* Colons in paths are no longer escaped. + # httr2 1.2.0 ## Lifecycle changes diff --git a/R/url.R b/R/url.R index 2d3417c9..93be86c2 100644 --- a/R/url.R +++ b/R/url.R @@ -268,7 +268,7 @@ url_build <- function(url) { query <- I(url_query_build(url$query)) } - curl::curl_modify_url( + url <- curl::curl_modify_url( scheme = url$scheme, host = url$hostname, user = url$username, @@ -278,6 +278,17 @@ url_build <- function(url) { query = query, fragment = url$fragment ) + + # Workaround https://github.com/curl/curl/issues/17977 + # curl url parser esacapes colons in paths which google seems to use + # quite frequently. So we hack the problem away for now, restoring the + # behaviour of httr2 1.1.2 + if (grepl("%3A", url, fixed = TRUE)) { + path <- curl::curl_parse_url(url, decode = FALSE)$path + path <- gsub("%3A", ":", path, fixed = TRUE) + url <- curl::curl_modify_url(url, path = I(path)) + } + url } #' Parse query parameters and/or build a string diff --git a/tests/testthat/test-url.R b/tests/testthat/test-url.R index cecc931a..b01ab474 100644 --- a/tests/testthat/test-url.R +++ b/tests/testthat/test-url.R @@ -101,6 +101,13 @@ test_that("encodes params and paths", { ) }) +test_that("colons in paths are left as is", { + expect_equal( + url_modify("https://example.com", path = "a:b/foo bar/"), + "https://example.com/a:b/foo%20bar/" + ) +}) + test_that("checks various query formats", { url <- "http://example.com"