Skip to content

Commit

Permalink
Add workaround for anchor links (#367)
Browse files Browse the repository at this point in the history
Bug in libcurl 8.11.1 and lower: curl/curl#15836
  • Loading branch information
jeroen authored Dec 27, 2024
1 parent 509f10d commit 5ea5c9a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 6 additions & 0 deletions R/parser.R
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ curl_parse_url <- function(url, baseurl = NULL, decode = TRUE, params = TRUE){
stopifnot(is.character(url))
stopifnot(length(url) == 1)
baseurl < as.character(baseurl)

# Workaround for #366
if(length(baseurl) && substr(url, 1, 1) == '#'){
url <- sub('(#.*)?$', url, baseurl)
}

result <- .Call(R_parse_url, url, baseurl)
if(inherits(result, 'ada')){
result <- normalize_ada(result)
Expand Down
5 changes: 3 additions & 2 deletions tests/testthat/test-parser.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ test_that("Basic URL parser",{
})

test_that("Relative links need a baseurl",{
base <- 'https://jerry:secret@google.com:888/foo/bar#nothing'
base <- 'https://jerry:secret@google.com:888/foo/bar?x=1#nothing'
out1 <- curl_parse_url("/test1", base) #NB: curl does but ADA does not have nice error messages
out2 <- curl_parse_url("./test2", base)
out3 <- curl_parse_url("#bla", base)
expect_equal(out1$url, "https://jerry:secret@google.com:888/test1")
expect_equal(out2$url, "https://jerry:secret@google.com:888/foo/test2")
expect_equal(out3$url, "https://jerry:secret@google.com:888/foo/bar?x=1#bla")
expect_error(curl_parse_url("/test1"))
expect_error(curl_parse_url("./test2"))
})
Expand Down Expand Up @@ -49,4 +51,3 @@ test_that("Decoding parameters", {
out <- curl_parse_url('https://www.test.com/bla?tv=tom%26jerry&math=1%2B1+%3D+2&empty')
expect_equal(out$params, c(tv = "tom&jerry", math = "1+1 = 2", empty = ""))
})

0 comments on commit 5ea5c9a

Please sign in to comment.