Skip to content

Commit

Permalink
improve handling of Windows paths (#2069)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinushey committed Jan 7, 2025
1 parent 281ddcb commit d6fe08d
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 3 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@

# renv 1.1.0 (UNRELEASED)

* Fixed an issue where `RENV_CONFIG_EXTERNAL_LIBRARIES` was incorrectly
split when using Windows paths. (#2069)

* Fixed an issue where `renv` failed to restore packages installed from
r-universe when the associated lockfile record had no `RemoteRef` field.
(#2068)
Expand Down
23 changes: 22 additions & 1 deletion R/config.R
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,28 @@ renv_config_decode_envvar <- function(envname, envval) {
else
"\\s*,\\s*"

strsplit(envval, pattern, perl = TRUE)[[1L]]
values <- strsplit(envval, pattern, perl = TRUE)[[1L]]

# fix up single-letter paths for Windows
# https://github.com/rstudio/renv/issues/2069
result <- stack(mode = "character")

i <- 1L
while (i <= length(values)) {

if (nchar(values[[i]]) == 1L) {
value <- paste(values[[i]], values[[i + 1L]], sep = ":")
result$push(value)
i <- i + 2L
} else {
value <- values[[i]]
result$push(value)
i <- i + 1L
}

}

result$data()

}

Expand Down
50 changes: 48 additions & 2 deletions tests/testthat/test-config.R
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,9 @@ test_that("we can query the default configuration values without issue", {

test_that("multiple library paths can be set in RENV_CONFIG_EXTERNAL_LIBRARIES", {

renv_scope_envvars(RENV_CONFIG_EXTERNAL_LIBRARIES = "a:b:c")
renv_scope_envvars(RENV_CONFIG_EXTERNAL_LIBRARIES = "/a:/b:/c")
libpaths <- config$external.libraries()
expect_equal(libpaths, c("a", "b", "c"))
expect_equal(libpaths, c("/a", "/b", "/c"))

})

Expand All @@ -102,3 +102,49 @@ test_that("cache symlinks are disabled if the cache and project library lie in d


})

test_that("RENV_CONFIG_EXTERNAL_LIBRARIES is decoded appropriately", {

envname <- "RENV_CONFIG_EXTERNAL_LIBRARIES"

expect_equal(
renv_config_decode_envvar(envname, "/apple"),
"/apple"
)

expect_equal(
renv_config_decode_envvar(envname, "C:/apple"),
"C:/apple"
)

expect_equal(
renv_config_decode_envvar(envname, "C:/apple:C:/banana"),
c("C:/apple", "C:/banana")
)

expect_equal(
renv_config_decode_envvar(envname, "C:/apple;C:/banana"),
c("C:/apple", "C:/banana")
)

expect_equal(
renv_config_decode_envvar(envname, "C:/apple,C:/banana"),
c("C:/apple", "C:/banana")
)

expect_equal(
renv_config_decode_envvar(envname, "/apple:/banana"),
c("/apple", "/banana")
)

expect_equal(
renv_config_decode_envvar(envname, "/apple;/banana"),
c("/apple", "/banana")
)

expect_equal(
renv_config_decode_envvar(envname, "/apple,/banana"),
c("/apple", "/banana")
)

})
1 change: 1 addition & 0 deletions tests/testthat/test-envvar.R
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

test_that("can add before or after", {
path_string <- function(...) {
paste(c(...), collapse = .Platform$path.sep)
Expand Down

0 comments on commit d6fe08d

Please sign in to comment.