Skip to content

Commit 630ca2d

Browse files
authored
Escape { } in message for cli abort (#295)
Curly braces in Quarto CLI error messages are now escaped to prevent them from being interpreted as `cli` formatting syntax (closes #293).
1 parent 7309955 commit 630ca2d

File tree

8 files changed

+55
-2
lines changed

8 files changed

+55
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,5 @@ docs
88
/doc/
99
/Meta/
1010
**/.quarto/
11+
12+
/.luarc.json

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: quarto
22
Title: R Interface to 'Quarto' Markdown Publishing System
3-
Version: 1.5.1.9000
3+
Version: 1.5.1.9002
44
Authors@R: c(
55
person("JJ", "Allaire", , "[email protected]", role = "aut",
66
comment = c(ORCID = "0000-0003-0174-9868")),

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
- `.libPaths()` from the calling R session will now be passed by default to all call to quarto as a subprocess. This should solve issue with **pkgdown** or when building vignettes.
44

5+
- Curly braces in Quarto CLI error messages are now escaped to prevent them from being interpreted as `cli` formatting syntax (#293).
6+
57
# quarto 1.5.1
68

79
- Make sure tests pass on CRAN checks even when Quarto is not installed by adding a gihub action to test when no quarto is available. Also fix tests that were

R/quarto.R

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,11 @@ quarto_run <- function(
159159
custom_env <- c("current", custom_env)
160160
}
161161

162+
# Special case for tests to force hiding echo
163+
if (is_testing() && getOption("quarto.tests.hide_echo", FALSE)) {
164+
echo <- FALSE
165+
}
166+
162167
res <- withCallingHandlers(
163168
processx::run(
164169
quarto_bin,
@@ -346,7 +351,7 @@ wrap_quarto_error <- function(cnd, args, .call = rlang::caller_env()) {
346351
msg <- c(
347352
msg,
348353
" " = paste0(rep("-", nchar(msg)), collapse = ""),
349-
quarto_error_msg
354+
cli_escape(quarto_error_msg)
350355
)
351356
}
352357

R/utils.R

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,12 @@ warn_or_error <- function(message, ..., .envir = parent.frame()) {
162162
}
163163
}
164164

165+
cli_escape <- function(x) {
166+
x <- gsub("{", "{{", x, fixed = TRUE)
167+
x <- gsub("}", "}}", x, fixed = TRUE)
168+
x
169+
}
170+
165171
# inline knitr:::merge_list()
166172
merge_list <- function(x, y) {
167173
x[names(y)] <- y
@@ -213,3 +219,7 @@ is_empty_dir <- function(dir) {
213219
files <- list.files(dir, all.files = TRUE, no.. = TRUE)
214220
length(files) == 0
215221
}
222+
223+
is_testing <- function() {
224+
identical(Sys.getenv("TESTTHAT"), "true")
225+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Pandoc = function(doc)
2+
internal_error()
3+
end
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
format: latex
3+
filters:
4+
- error.lua
5+
---
6+
7+
content

tests/testthat/test-render.R

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,3 +124,27 @@ test_that("quarto_render allows to pass output-file meta", {
124124
expect_true(file.exists("final_report.html"))
125125
expect_true(file.exists("final_report.docx"))
126126
})
127+
128+
129+
test_that("{ } are escaped correctly in abort message", {
130+
skip_if_no_quarto()
131+
proj <- test_path("resources", "cli_error")
132+
withr::local_dir(proj)
133+
keep_files <- list.files(".", all.files = TRUE)
134+
withr::defer({
135+
unlink(
136+
setdiff(list.files(".", all.files = TRUE), keep_files),
137+
recursive = TRUE,
138+
force = TRUE
139+
)
140+
})
141+
withr::local_options(quarto.tests.hide_echo = TRUE)
142+
expect_error(
143+
quarto_render(
144+
"pdf-error.qmd",
145+
quiet = FALSE,
146+
quarto_args = c("--log", "test.log")
147+
),
148+
regexp = "Error returned by quarto CLI(.*)nil value \\(global 'internal_error'\\)"
149+
)
150+
})

0 commit comments

Comments
 (0)