diff --git a/NEWS.md b/NEWS.md index 229ebb30f..204f69058 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,9 @@ # nanonext (development version) +#### Updates + +* `parse_url()` drops 'rawurl', 'host' and 'requri' from the output vector as these can be derived from the other parts. + # nanonext 1.7.1 #### Updates diff --git a/R/utils.R b/R/utils.R index 987850367..e9004ec79 100644 --- a/R/utils.R +++ b/R/utils.R @@ -114,15 +114,12 @@ random <- function(n = 1L, convert = TRUE) .Call(rnng_random, n, convert) #' #' @param url character string containing a URL. #' -#' @return A named character vector of length 10, comprising: +#' @return A named character vector of length 7, comprising: #' \itemize{ -#' \item `rawurl` - the unparsed URL string. #' \item `scheme` - the URL scheme, such as "http" or "inproc" (always lower #' case). -#' \item `userinfo` - the username and password if supplied in the URL -#' string. -#' \item `host` - the full host part of the URL, including the port if -#' present (separated by a colon). +#' \item `userinfo` - the username and password (if supplied in the URL +#' string). #' \item `hostname` - the name of the host. #' \item `port` - the port (if not specified, the default port if defined by #' the scheme). @@ -130,7 +127,6 @@ random <- function(n = 1L, convert = TRUE) .Call(rnng_random, n, convert) #' \item `query` - the query info (typically following ? in the URL). #' \item `fragment` - used for specifying an anchor, the part after # in a #' URL. -#' \item `requri` - the full Request-URI (path\[?query\]\[#fragment\]). #' } #' Values that cannot be determined are represented by an empty string `""`. #' diff --git a/man/parse_url.Rd b/man/parse_url.Rd index 475620406..407949265 100644 --- a/man/parse_url.Rd +++ b/man/parse_url.Rd @@ -10,15 +10,12 @@ parse_url(url) \item{url}{character string containing a URL.} } \value{ -A named character vector of length 10, comprising: +A named character vector of length 7, comprising: \itemize{ -\item \code{rawurl} - the unparsed URL string. \item \code{scheme} - the URL scheme, such as "http" or "inproc" (always lower case). -\item \code{userinfo} - the username and password if supplied in the URL -string. -\item \code{host} - the full host part of the URL, including the port if -present (separated by a colon). +\item \code{userinfo} - the username and password (if supplied in the URL +string). \item \code{hostname} - the name of the host. \item \code{port} - the port (if not specified, the default port if defined by the scheme). @@ -26,7 +23,6 @@ the scheme). \item \code{query} - the query info (typically following ? in the URL). \item \code{fragment} - used for specifying an anchor, the part after # in a URL. -\item \code{requri} - the full Request-URI (path[?query][#fragment]). } Values that cannot be determined are represented by an empty string \code{""}. } diff --git a/src/utils.c b/src/utils.c index 9a390d4dd..263599d55 100644 --- a/src/utils.c +++ b/src/utils.c @@ -49,19 +49,16 @@ SEXP rnng_url_parse(SEXP url) { ERROR_OUT(xc); SEXP out; - const char *names[] = {"rawurl", "scheme", "userinfo", "host", "hostname", - "port", "path", "query", "fragment", "requri", ""}; + const char *names[] = {"scheme", "userinfo", "hostname", "port", "path", + "query", "fragment", ""}; PROTECT(out = Rf_mkNamed(STRSXP, names)); - SET_STRING_ELT(out, 0, Rf_mkChar(urlp->u_rawurl)); - SET_STRING_ELT(out, 1, Rf_mkChar(urlp->u_scheme == NULL ? "" : urlp->u_scheme)); - SET_STRING_ELT(out, 2, Rf_mkChar(urlp->u_userinfo == NULL ? "" : urlp->u_userinfo)); - SET_STRING_ELT(out, 3, Rf_mkChar(urlp->u_host == NULL ? "" : urlp->u_host)); - SET_STRING_ELT(out, 4, Rf_mkChar(urlp->u_hostname == NULL ? "" : urlp->u_hostname)); - SET_STRING_ELT(out, 5, Rf_mkChar(urlp->u_port == NULL ? "" : urlp->u_port)); - SET_STRING_ELT(out, 6, Rf_mkChar(urlp->u_path == NULL ? "" : urlp->u_path)); - SET_STRING_ELT(out, 7, Rf_mkChar(urlp->u_query == NULL ? "" : urlp->u_query)); - SET_STRING_ELT(out, 8, Rf_mkChar(urlp->u_fragment == NULL ? "" : urlp->u_fragment)); - SET_STRING_ELT(out, 9, Rf_mkChar(urlp->u_requri == NULL ? "" : urlp->u_requri)); + SET_STRING_ELT(out, 0, Rf_mkChar(urlp->u_scheme == NULL ? "" : urlp->u_scheme)); + SET_STRING_ELT(out, 1, Rf_mkChar(urlp->u_userinfo == NULL ? "" : urlp->u_userinfo)); + SET_STRING_ELT(out, 2, Rf_mkChar(urlp->u_hostname == NULL ? "" : urlp->u_hostname)); + SET_STRING_ELT(out, 3, Rf_mkChar(urlp->u_port == NULL ? "" : urlp->u_port)); + SET_STRING_ELT(out, 4, Rf_mkChar(urlp->u_path == NULL ? "" : urlp->u_path)); + SET_STRING_ELT(out, 5, Rf_mkChar(urlp->u_query == NULL ? "" : urlp->u_query)); + SET_STRING_ELT(out, 6, Rf_mkChar(urlp->u_fragment == NULL ? "" : urlp->u_fragment)); nng_url_free(urlp); UNPROTECT(1); diff --git a/tests/tests.R b/tests/tests.R index e8a0af49e..69fbfa6ac 100644 --- a/tests/tests.R +++ b/tests/tests.R @@ -499,7 +499,7 @@ test_null(msleep(1)) test_null(msleep("a")) test_null(msleep(-1L)) test_type("character", urlp <- parse_url("://")) -test_equal(length(urlp), 10L) +test_equal(length(urlp), 7L) test_true(all(nzchar(parse_url("wss://use:r@[::1]/path?q=1#name")))) test_type("character", random()) test_equal(nchar(random(2)), 4L)