Skip to content

Commit

Permalink
Unterminated comments error now
Browse files Browse the repository at this point in the history
Instead of generating an empty string.

Closes #224.
  • Loading branch information
gaborcsardi committed Sep 25, 2021
1 parent c9f9cf9 commit 1fbb9a3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
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")
})

0 comments on commit 1fbb9a3

Please sign in to comment.