Skip to content

Commit

Permalink
Merge pull request #4336 from rstudio/bugfix/notebook-execution-chunk…
Browse files Browse the repository at this point in the history
…-options

sanitize certain chunk options before execution
  • Loading branch information
jmcphers committed Feb 21, 2019
2 parents a97ad3e + 2f66854 commit b171b1a
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/cpp/session/modules/SessionRmdNotebook.R
Expand Up @@ -647,11 +647,42 @@ assign(".rs.notebookVersion", envir = .rs.toolsEnv(), "1.0")
opts <- .rs.mergeLists(opts,
eval(substitute(knitr:::parse_params(code)),
envir = .GlobalEnv))

# convert T, F to TRUE, FALSE as appropriate
opts <- lapply(opts, function(opt) {
if (identical(opt, as.name("T")))
TRUE
else if (identical(opt, as.name("F")))
FALSE
else
opt
})

# convert language name objects to plain characters (these can occur in
# malformed expressions, and cause scalar conversion below to fail)
names <- vapply(opts, is.name, TRUE)
opts[names] <- as.character(opts[names])

# ensure that fields we expect to be logical are actually logical
# (sanitize invalid inputs here since they can break notebook execution)
fields <- list(
warning = TRUE,
message = TRUE,
error = FALSE
)

.rs.enumerate(fields, function(key, default) {

if (is.null(opts[[key]]))
next

opts[[key]] <<- tryCatch(
as.logical(opts[[key]]),
error = function(e) default
)

})

},
error = function(e) {})

Expand Down

0 comments on commit b171b1a

Please sign in to comment.