Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 comments in glue expression now throw an error (#227, @gaborcsardi)
* 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)
Expand Down
3 changes: 3 additions & 0 deletions src/glue.c
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ SEXP glue_(SEXP x, SEXP f, SEXP open_arg, SEXP close_arg) {
} else if (state == double_quote) {
free(str);
Rf_error("Unterminated quote (\")");
} else if (state == comment) {
free(str);
Rf_error("Unterminated comment");
}

free(str);
Expand Down
7 changes: 7 additions & 0 deletions tests/testthat/test-glue.R
Original file line number Diff line number Diff line change
Expand Up @@ -429,3 +429,10 @@ test_that("unterminated quotes are error", {
expect_error(glue("{this doesn\"t work}"), "Unterminated quote")
expect_error(glue("{this doesn't work}"), "Unterminated quote")
})

test_that("unterminated comment", {
expect_error(glue("pre {1 + 5 # comment} post"), "Unterminated comment")
expect_error(glue("pre {1 + 5 # comment"), "Unterminated comment")

expect_equal(glue("pre {1 + 5 + #comment\n 4} post"), "pre 10 post")
})