| 1 |
|
| 2 |
renv_url_sanitize <- function(url) { |
| 3 |
sub("://[^@/]+@", "://", url) |
| 4 |
} |
| 5 |
|
| 6 |
renv_url_parse <- function(url) { |
| 7 |
|
| 8 |
pattern <- paste0( |
| 9 |
"^", |
| 10 |
"([^:]+://)?", # protocol |
| 11 |
"([^/?#]+)", # domain |
| 12 |
"(?:(/[^?#]*))?", # path |
| 13 |
"(?:[?]([^#]+))?", # parameters |
| 14 |
"(?:#(.*))?", # fragment |
| 15 |
"" |
| 16 |
) |
| 17 |
|
| 18 |
matches <- regmatches(url, regexec(pattern, url, perl = TRUE))[[1L]] |
| 19 |
if (length(matches) != 6L) |
| 20 |
stopf("couldn't parse url '%s'", url) |
| 21 |
|
| 22 |
matches <- as.list(matches) |
| 23 |
names(matches) <- c("url", "protocol", "domain", "path", "parameters", "fragment") |
| 24 |
|
| 25 |
# parse parameters into named list |
| 26 |
matches$parameters <- renv_properties_read( |
| 27 |
text = chartr("&", "\n", matches$parameters), |
| 28 |
delimiter = "=", |
| 29 |
dequote = FALSE, |
| 30 |
trim = FALSE |
| 31 |
) |
| 32 |
|
| 33 |
# return parsed URL |
| 34 |
matches |
| 35 |
|
| 36 |
} |
| 37 |
|