Skip to content

Commit

Permalink
fix #2043: replace parse(text) with xfun::parse_only() to avoid hangi…
Browse files Browse the repository at this point in the history
…ng the R session when the input is empty

also signal an error if the `site` field is not a function
  • Loading branch information
yihui committed May 18, 2021
1 parent d585df9 commit d8b1979
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: rmarkdown
Type: Package
Title: Dynamic Documents for R
Version: 2.8.2
Version: 2.8.3
Authors@R: c(
person("JJ", "Allaire", role = "aut", email = "[email protected]"),
person("Yihui", "Xie", role = c("aut", "cre"), email = "[email protected]", comment = c(ORCID = "0000-0003-0645-5666")),
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ rmarkdown 2.9

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

- `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).


rmarkdown 2.8
================================================================================
Expand Down
2 changes: 1 addition & 1 deletion R/html_resources.R
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ discover_rmd_resources <- function(rmd_file, discover_single_resource) {
# html_document to pick up dependencies
output_format <- output_format_from_yaml_front_matter(rmd_content)

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

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

Expand Down
4 changes: 2 additions & 2 deletions R/output_format.R
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ default_output_format <- function(input, output_yaml = NULL) {

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

create_output_format_function <- function(name) {
output_format_func <- eval(parse(text = name))
output_format_func <- eval(xfun::parse_only(name))
if (!is.function(output_format_func))
stop("YAML output format must evaluate to a function", call. = FALSE)
output_format_func
Expand Down
6 changes: 5 additions & 1 deletion R/render_site.R
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,11 @@ site_generator <- function(input = ".", output_format = NULL) {
front_matter <- yaml_front_matter(index)

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

# if it's in a subdir check to see if the generator supports nested files
Expand Down
6 changes: 3 additions & 3 deletions R/shiny_prerendered.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ shiny_prerendered_app <- function(input_rmd, render_args) {
assign(".shiny_prerendered_server_start_code", server_start_code, envir = server_envir)

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

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

Expand Down Expand Up @@ -521,7 +521,7 @@ shiny_prerendered_evaluate_hook <- function(input) {

# otherwise parse so we can throw an error for invalid code
else {
parse(text = code)
xfun::parse_only(code)
list()
}
}
Expand Down

0 comments on commit d8b1979

Please sign in to comment.