Skip to content

Commit c57710f

Browse files
committed
Make sure to source the file in a child environment
1 parent 1b5d933 commit c57710f

File tree

5 files changed

+16
-6
lines changed

5 files changed

+16
-6
lines changed

R/Plumber.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -300,9 +300,11 @@ Plumber <- R6Class(
300300
},
301301
#' @description Parses a plumber file and updates the app according to it
302302
#' @param file The path to a file to parse
303-
#' @param env The environment to evaluate the content of the file in
303+
#' @param env The parent environment to the environment the file should be
304+
#' evaluated in
304305
parse_file = function(file, env = caller_env()) {
305-
parsed <- parse_plumber_file(file, env)
306+
eval_env <- new.env(parent = env)
307+
parsed <- parse_plumber_file(file, eval_env)
306308
if (!parsed$route[[1]]$empty) {
307309
if (!self$request_router$has_route(names(parsed$route))) {
308310
self$add_route(names(parsed$route))

R/api.R

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,9 @@
4343
#' plain text but rely on e.g. the keyring package for storage. Even so, if
4444
#' requests are send over HTTP (not HTTPS) then anyone can read the secret and
4545
#' use it
46-
#' @param env The environment the files should be parsed in
46+
#' @param env The parent environment to the environment the files should be
47+
#' evaluated in. Each file will be evaluated in it's own environment so they
48+
#' don't interfere with each other
4749
#'
4850
#' @return A Plumber object
4951
#'

R/parse_plumber_file.R

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ parse_plumber_file <- function(path, env = caller_env()) {
3232
if (!fs::file_exists(path)) {
3333
cli::cli_abort("{.arg path} must point to an existing file", call = env)
3434
}
35+
36+
source(path, local = env, verbose = FALSE)
37+
3538
file <- readLines(path)
3639
file <- sub("^#([^\\*])", "##\\1", file)
3740
file <- sub("^#\\*", "#'", file)

man/Plumber.Rd

Lines changed: 3 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/api.Rd

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)