Skip to content

Commit e1a58a6

Browse files
authored
Ensure url_parse() doesn't decode path (#641)
Since we don't re-encode it
1 parent ae72fbc commit e1a58a6

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

R/url.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ url_parse <- function(url, base_url = NULL) {
2424
check_string(url)
2525
check_string(base_url, allow_null = TRUE)
2626

27-
curl <- curl::curl_parse_url(url, baseurl = base_url)
27+
curl <- curl::curl_parse_url(url, baseurl = base_url, decode = FALSE)
2828

2929
parsed <- list(
3030
scheme = curl$scheme,

tests/testthat/test-url.R

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ test_that("url_build validates its input", {
4444
expect_snapshot(url_build("abc"), error = TRUE)
4545
})
4646

47+
test_that("decodes query params but not paths", {
48+
url <- url_parse("http://example.com/a%20b?q=a%20b")
49+
expect_equal(url$path, "/a%20b")
50+
expect_equal(url$query$q, "a b")
51+
})
52+
4753
# modify url -------------------------------------------------------------
4854

4955
test_that("url_modify checks its inputs", {
@@ -69,6 +75,14 @@ test_that("no arguments is idempotent", {
6975
expect_equal(url_modify(url), url)
7076
})
7177

78+
test_that("can round-trip escaped components", {
79+
url <- "https://example.com/a%20b"
80+
expect_equal(url_modify(url), url)
81+
82+
url <- "https://example.com/?q=a%20b"
83+
expect_equal(url_modify(url), url)
84+
})
85+
7286
test_that("can accept query as a string or list", {
7387
url <- "http://test/"
7488

@@ -78,6 +92,14 @@ test_that("can accept query as a string or list", {
7892
expect_equal(url_modify(url, query = ""), "http://test/")
7993
expect_equal(url_modify(url, query = list()), "http://test/")
8094
})
95+
96+
test_that("automatically escapes query components", {
97+
expect_equal(
98+
url_modify("https://example.com", query = list(q = "a b")),
99+
"https://example.com/?q=a%20b"
100+
)
101+
})
102+
81103
test_that("checks various query formats", {
82104
url <- "http://example.com"
83105

0 commit comments

Comments
 (0)