diff --git a/R/parser.R b/R/parser.R index ad3597a..3345935 100644 --- a/R/parser.R +++ b/R/parser.R @@ -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) diff --git a/tests/testthat/test-parser.R b/tests/testthat/test-parser.R index 9d3ca16..e8fb2df 100644 --- a/tests/testthat/test-parser.R +++ b/tests/testthat/test-parser.R @@ -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")) }) @@ -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 = "")) }) -