Skip to content

Commit

Permalink
guard against unexpected user agent values (closes #1787)
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinushey committed Jan 9, 2024
1 parent de3af61 commit bdb8aa5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
8 changes: 7 additions & 1 deletion R/http.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@

renv_http_useragent <- function() {

# https://github.com/rstudio/renv/issues/1787
agent <- getOption("renv.http.useragent", default = getOption("HTTPUserAgent"))
agent %||% renv_http_useragent_default()
if (is.character(agent) && length(agent) == 1L)
return(agent)

renv_http_useragent_default()

}

renv_http_useragent_default <- function() {
Expand Down
13 changes: 13 additions & 0 deletions tests/testthat/test-http.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

test_that("renv handles unexpected user agent values", {

# https://github.com/rstudio/renv/issues/1787
renv_scope_options(HTTPUserAgent = character())
agent <- renv_http_useragent()
expect_equal(agent, renv_http_useragent_default())

renv_scope_options(HTTPUserAgent = NULL)
agent <- renv_http_useragent()
expect_equal(agent, renv_http_useragent_default())

})

0 comments on commit bdb8aa5

Please sign in to comment.