diff --git a/NEWS.md b/NEWS.md index bec0bfa..8926803 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # glue 1.4.2 +* Unterminated quotes in glue expressions now throw an error (#226, @gaborcsardi) * `glue_safe()` gives a slightly nicer error message * The required version of R is now 3.2 (#189) * `glue_sql()` now collapses `DBI::SQL()` elements correctly (#192 @shrektan) diff --git a/src/glue.c b/src/glue.c index 12cdee4..2682565 100644 --- a/src/glue.c +++ b/src/glue.c @@ -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); diff --git a/tests/testthat/test-glue.R b/tests/testthat/test-glue.R index a9d8ed1..f4507e1 100644 --- a/tests/testthat/test-glue.R +++ b/tests/testthat/test-glue.R @@ -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") +})