Skip to content

Commit

Permalink
[named_region] add checks for named region string. closes #1095 (#1097)
Browse files Browse the repository at this point in the history
  • Loading branch information
JanMarvin committed Aug 1, 2024
1 parent d058b8a commit eba39c4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions R/class-workbook.R
Original file line number Diff line number Diff line change
Expand Up @@ -9395,6 +9395,9 @@ wbWorkbook <- R6::R6Class(
) {
name <- replace_legal_chars(name)

if (!grepl("^[\\p{L}_][^\\s]*$", name, perl = TRUE))
stop("named region must begin with a letter or an underscore and not contain whitespace(s).")

# special names

## print
Expand Down
10 changes: 10 additions & 0 deletions tests/testthat/test-named_regions.R
Original file line number Diff line number Diff line change
Expand Up @@ -524,3 +524,13 @@ test_that("local_sheet works", {
expect_equal(exp, got)

})

test_that("named region checks work", {
wb <- wb_workbook()$add_worksheet()

expect_error(wb$add_named_region(dims = "A1", name = 1), "letter or an underscore")
expect_error(wb$add_named_region(dims = "B1", name = "1"), "letter or an underscore")
expect_silent(wb$add_named_region(dims = "C1", name = stringi::stri_unescape_unicode("\\u00e4")))
expect_error(wb$add_named_region(dims = "D1", name = "a b"), "letter or an underscore")
expect_error(wb$add_named_region(dims = "D1", name = "A1"), "cell reference")
})

0 comments on commit eba39c4

Please sign in to comment.