Skip to content

Commit

Permalink
Make untermiated quotes error
Browse files Browse the repository at this point in the history
Closes #219.
  • Loading branch information
gaborcsardi committed Sep 25, 2021
1 parent 9d88032 commit 2c9459b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,12 @@ SEXP glue_(SEXP x, SEXP f, SEXP open_arg, SEXP close_arg) {
if (state == delim) {
free(str);
Rf_error("Expecting '%s'", close);
} else if (state == single_quote) {
free(str);
Rf_error("Unterminated quote (')");
} else if (state == double_quote) {
free(str);
Rf_error("Unterminated quote (\")");
}

free(str);
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-glue.R
Original file line number Diff line number Diff line change
Expand Up @@ -424,3 +424,8 @@ test_that("+ method for glue works", {
x <- 1
expect_identical(glue("x = ") + "{x}", glue("x = {x}"))
})

test_that("unterminated quotes are error", {
expect_error(glue("{this doesn\"t work}"), "Unterminated quote")
expect_error(glue("{this doesn't work}"), "Unterminated quote")
})

0 comments on commit 2c9459b

Please sign in to comment.