Skip to content

Commit eebdfda

Browse files
committed
Restrict name strings in scaffolding to avoid subsequent problems
1 parent 3e4563b commit eebdfda

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

R/reacttools.R

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
# A robust name string is a valid
2+
# - CSS class
3+
# - JavaScript variable name
4+
# - R variable name
5+
robustName <- "^[[:alpha:]_][[:alnum:]_]*$"
6+
17
isUpper <- function(s) {
28
grepl("^[[:upper:]]+$", s)
39
}

R/scaffold_utils.R

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,10 @@ getPackage <- function() {
5353
read.dcf('DESCRIPTION')[[1,"Package"]]
5454
}
5555

56-
validName <- function(name) {
57-
grepl("^[[:alpha:]_][[:alnum:]_]*$", name)
58-
}
59-
6056
# Constraining names prevents the user from encountering obscure CSS problems
6157
# and JavaScript errors after scaffolding.
6258
assertNameValid <- function(name) {
63-
if (!validName(name)) {
59+
if (!grepl(robustName, name)) {
6460
msg <- sprintf("Name '%s' is invalid, names must begin with an alphabetic character and must contain only alphabetic and numeric characters", name)
6561
stop(msg, call. = FALSE)
6662
}

0 commit comments

Comments
 (0)