Skip to content

Commit

Permalink
Make unterminated quotes error (#226)
Browse files Browse the repository at this point in the history
Co-authored-by: Jim Hester <james.f.hester@gmail.com>
  • Loading branch information
gaborcsardi and jimhester authored Sep 27, 2021
1 parent 5673c06 commit 9e5c656
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
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 9e5c656

Please sign in to comment.