Skip to content

Commit 9baf978

Browse files
authored
Hack around colon escaping (#781)
1 parent fcae25a commit 9baf978

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# httr2 (development version)
22

3+
* Colons in paths are no longer escaped.
4+
35
# httr2 1.2.0
46

57
## Lifecycle changes

R/url.R

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ url_build <- function(url) {
268268
query <- I(url_query_build(url$query))
269269
}
270270

271-
curl::curl_modify_url(
271+
url <- curl::curl_modify_url(
272272
scheme = url$scheme,
273273
host = url$hostname,
274274
user = url$username,
@@ -278,6 +278,17 @@ url_build <- function(url) {
278278
query = query,
279279
fragment = url$fragment
280280
)
281+
282+
# Workaround https://github.com/curl/curl/issues/17977
283+
# curl url parser esacapes colons in paths which google seems to use
284+
# quite frequently. So we hack the problem away for now, restoring the
285+
# behaviour of httr2 1.1.2
286+
if (grepl("%3A", url, fixed = TRUE)) {
287+
path <- curl::curl_parse_url(url, decode = FALSE)$path
288+
path <- gsub("%3A", ":", path, fixed = TRUE)
289+
url <- curl::curl_modify_url(url, path = I(path))
290+
}
291+
url
281292
}
282293

283294
#' Parse query parameters and/or build a string

tests/testthat/test-url.R

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,13 @@ test_that("encodes params and paths", {
101101
)
102102
})
103103

104+
test_that("colons in paths are left as is", {
105+
expect_equal(
106+
url_modify("https://example.com", path = "a:b/foo bar/"),
107+
"https://example.com/a:b/foo%20bar/"
108+
)
109+
})
110+
104111
test_that("checks various query formats", {
105112
url <- "http://example.com"
106113

0 commit comments

Comments
 (0)