8000 URL's scheme parser is compliant with RFC 3986 by ymarcon · Pull Request #615 · r-lib/httr · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

URL's scheme parser is compliant with RFC 3986 #615

New issue < 8000 details-dialog class="Box Box--overlay d-flex flex-column anim-fade-in fast overflow-auto" aria-label="Sign up for GitHub">

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 2 commits into from
Apr 3, 2020
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
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# httr (development version)

* `parse_url()` now refers to RFC3986 for the parsing of the URL's
scheme, with a bit more permissive syntax (@ymarcon, #615).

# httr 1.4.1

* Remove the default `cainfo` option on Windows. Providing a CA bundle is not
Expand Down
8 changes: 4 additions & 4 deletions R/url.r
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Good example for testing
# http://stevenlevithan.com/demo/parseuri/js/

#' Parse and build urls according to RFC1808.
#' Parse and build urls according to RFC3986.
#'
#' See <http://tools.ietf.org/html/rfc1808.html> for details of parsing
#' See <https://tools.ietf.org/html/rfc3986> for details of parsing
#' algorithm.
#'
#' @param url For `parse_url` a character vector (of length 1) to parse
Expand All @@ -24,7 +24,7 @@
#' parse_url("http://google.com/")
#' parse_url("http://google.com:80/")
#' parse_url("http://google.com:80/?a=1&b=2")
#'
#'
#' url <- parse_url("http://google.com/")
#' url$scheme <- "https"
#' url$query <- list(q = "hello")
Expand All @@ -45,7 +45,7 @@ parse_url <- function(url) {
}

fragment <- pull_off("#(.*)$")
scheme <- pull_off("^([[:alpha:]+.-]+):")
scheme <- pull_off("^([[:alpha:]][[:alpha:][:digit:]+.-]*):")
netloc <- pull_off("^//([^/?]*)/?")

if (identical(netloc, "")) { # corresponds to ///
Expand Down
4 changes: 2 additions & 2 deletions man/parse_url.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions tests/testthat/test-url.r
64CA
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,36 @@ test_that("parse_url preserves leading / in path", {
expect_equal(url$path, "/tmp/foobar")
})

test_that("scheme starts with alpha", {
url <- parse_url("+ab://host/tmp/foobar")
expect_equal(url$scheme, NULL)
})

test_that("scheme can contain digits", {
url <- parse_url("ab1://host/tmp/foobar")
expect_equal(url$scheme, "ab1")
})

test_that("scheme can contain plus", {
url <- parse_url("a+b://host/tmp/foobar")
expect_equal(url$scheme, "a+b")
})

test_that("scheme can contain period", {
url <- parse_url("a.b://host/tmp/foobar")
expect_equal(url$scheme, "a.b")
})

test_that("scheme can contain hyphen", {
url <- parse_url("a-b://host/tmp/foobar")
expect_equal(url$scheme, "a-b")
})

test_that("scheme can be a single character", {
url <- parse_url("a://host/tmp/foobar")
expect_equal(url$scheme, "a")
})

# compose_query -----------------------------------------------------------

test_that("I() prevents escaping", {
Expand Down
0