Skip to content

Ensure url_parse() doesn't decode path #641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 13, 2025
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 R/url.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ url_parse <- function(url, base_url = NULL) {
check_string(url)
check_string(base_url, allow_null = TRUE)

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

parsed <- list(
scheme = curl$scheme,
Expand Down
22 changes: 22 additions & 0 deletions tests/testthat/test-url.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ test_that("url_build validates its input", {
expect_snapshot(url_build("abc"), error = TRUE)
})

test_that("decodes query params but not paths", {
url <- url_parse("http://example.com/a%20b?q=a%20b")
expect_equal(url$path, "/a%20b")
expect_equal(url$query$q, "a b")
})

# modify url -------------------------------------------------------------

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

test_that("can round-trip escaped components", {
url <- "https://example.com/a%20b"
expect_equal(url_modify(url), url)

url <- "https://example.com/?q=a%20b"
expect_equal(url_modify(url), url)
})

test_that("can accept query as a string or list", {
url <- "http://test/"

Expand All @@ -78,6 +92,14 @@ test_that("can accept query as a string or list", {
expect_equal(url_modify(url, query = ""), "http://test/")
expect_equal(url_modify(url, query = list()), "http://test/")
})

test_that("automatically escapes query components", {
expect_equal(
url_modify("https://example.com", query = list(q = "a b")),
"https://example.com/?q=a%20b"
)
})

test_that("checks various query formats", {
url <- "http://example.com"

Expand Down
Loading