Skip to content

Commit d8b1979

Browse files
committed
fix #2043: replace parse(text) with xfun::parse_only() to avoid hanging the R session when the input is empty
also signal an error if the `site` field is not a function
1 parent d585df9 commit d8b1979

6 files changed

Lines changed: 14 additions & 8 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: rmarkdown
22
Type: Package
33
Title: Dynamic Documents for R
4-
Version: 2.8.2
4+
Version: 2.8.3
55
Authors@R: c(
66
person("JJ", "Allaire", role = "aut", email = "jj@rstudio.com"),
77
person("Yihui", "Xie", role = c("aut", "cre"), email = "xie@yihui.name", comment = c(ORCID = "0000-0003-0645-5666")),

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ rmarkdown 2.9
55

66
- Floating ToC in `html_document` can now hide headings with unnumbered and unlisted classes (thanks, @atusy, #1993).
77

8+
- `rmarkdown::site_generator()` can hang session waiting for input when the `site` field is not found in the YAML frontmatter of `index.Rmd` (thanks, @kevinushey @mirh, #2043).
9+
810

911
rmarkdown 2.8
1012
================================================================================

R/html_resources.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ discover_rmd_resources <- function(rmd_file, discover_single_resource) {
332332
# html_document to pick up dependencies
333333
output_format <- output_format_from_yaml_front_matter(rmd_content)
334334

335-
output_format_function <- eval(parse(text = output_format$name))
335+
output_format_function <- eval(xfun::parse_only(output_format$name))
336336

337337
override_output_format <- if (!is_pandoc_to_html(output_format_function()$pandoc)) "html_document"
338338

R/output_format.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ default_output_format <- function(input, output_yaml = NULL) {
402402

403403
# look up the formals of the output function to get the full option list and
404404
# merge against the explicitly set list
405-
format_function <- eval(parse(text = format$name))
405+
format_function <- eval(xfun::parse_only(format$name))
406406
format$options <- merge_lists(as.list(formals(format_function)),
407407
format$options,
408408
recursive = FALSE)
@@ -615,7 +615,7 @@ output_format_string_from_ext <- function(output_file) {
615615
}
616616

617617
create_output_format_function <- function(name) {
618-
output_format_func <- eval(parse(text = name))
618+
output_format_func <- eval(xfun::parse_only(name))
619619
if (!is.function(output_format_func))
620620
stop("YAML output format must evaluate to a function", call. = FALSE)
621621
output_format_func

R/render_site.R

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,11 @@ site_generator <- function(input = ".", output_format = NULL) {
282282
front_matter <- yaml_front_matter(index)
283283

284284
# create the site generator (passing the root dir)
285-
create_site_generator <- eval(parse(text = front_matter$site))
285+
create_site_generator <- eval(xfun::parse_only(front_matter$site))
286+
if (!is.function(create_site_generator)) stop(
287+
"Cannot find the site generator from the 'site' field in YAML frontmatter ",
288+
"of '", index, "'."
289+
)
286290
generator <- create_site_generator(root)
287291

288292
# if it's in a subdir check to see if the generator supports nested files

R/shiny_prerendered.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ shiny_prerendered_app <- function(input_rmd, render_args) {
2828
assign(".shiny_prerendered_server_start_code", server_start_code, envir = server_envir)
2929

3030
# execute the startup code (server_start_context + context="data" loading)
31-
eval(parse(text = server_start_context), envir = server_envir)
31+
eval(xfun::parse_only(server_start_context), envir = server_envir)
3232
shiny_prerendered_data_load(input_rmd, server_envir)
3333

3434
# lock the environment to prevent inadvertant assignments
@@ -39,7 +39,7 @@ shiny_prerendered_app <- function(input_rmd, render_args) {
3939
.server_context <- shiny_prerendered_extract_context(html_lines, "server")
4040
server_envir$.server_context <- .server_context
4141
server <- function(input, output, session) {
42-
eval(parse(text = .server_context))
42+
eval(xfun::parse_only(.server_context))
4343
}
4444
environment(server) <- new.env(parent = server_envir)
4545

@@ -521,7 +521,7 @@ shiny_prerendered_evaluate_hook <- function(input) {
521521

522522
# otherwise parse so we can throw an error for invalid code
523523
else {
524-
parse(text = code)
524+
xfun::parse_only(code)
525525
list()
526526
}
527527
}

0 commit comments

Comments
 (0)