Skip to content

Commit 6e54da6

Browse files
committed
[review] Guard against problematic characters in dataset names
1 parent 58d0357 commit 6e54da6

6 files changed

Lines changed: 78 additions & 4 deletions

File tree

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: dv.listings
22
Type: Package
33
Title: Data listings module
4-
Version: 4.3.4-9002
4+
Version: 4.3.4-9003
55
Authors@R:
66
c(
77
person("Boehringer-Ingelheim Pharma GmbH & Co.KG", role = c("cph", "fnd")),

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# dv.listings 4.3.4-9003
2+
- Review functionality:
3+
- Guard against problematic characters in dataset names
4+
15
# dv.listings 4.3.4-9002
26
- Review functionality:
37
- Cope with initially empty datasets

R/mod_listings.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ check_mod_listings <- function(afmm, datasets, module_id, dataset_names,
993993
)
994994
)
995995

996-
check_review_parameter(datasets, dataset_names, review, err)
996+
check_review_parameter(afmm, datasets, dataset_names, review, err)
997997

998998
res <- list(errors = err[["messages"]])
999999
return(res)

R/review.R

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,10 @@ REV_report_changes <- function(h0, h1, verbose = FALSE) {
12901290

12911291
#' Early error feedback function for the optional review parameter
12921292
#'
1293+
#' @param afmm
1294+
#'
1295+
#' Pass-through of the server afmm parameter.
1296+
#'
12931297
#' @param datasets `[list(data.frame)]`
12941298
#'
12951299
#' Available datasets for review.
@@ -1307,7 +1311,7 @@ REV_report_changes <- function(h0, h1, verbose = FALSE) {
13071311
#' the configuration of the review parameter will be placed here.
13081312
#'
13091313
#' @export
1310-
check_review_parameter <- function(datasets, dataset_names, review, err) {
1314+
check_review_parameter <- function(afmm, datasets, dataset_names, review, err) {
13111315
if (is.null(review)) return(NULL)
13121316
ok <- CM$assert(
13131317
container = err,
@@ -1443,4 +1447,48 @@ check_review_parameter <- function(datasets, dataset_names, review, err) {
14431447
)
14441448
}
14451449
}
1450+
if (!ok) return(NULL)
1451+
1452+
# https://en.wikipedia.org/wiki/Filename#Problematic_characters
1453+
problematic_chars <- c("/", "\\\\", "?", "%", "*", ":", "|", '"', "<", ">", ".", ",", ";", "=")
1454+
problematic_chars_regexp <- paste("([", paste(problematic_chars, collapse = ""), "])")
1455+
1456+
report_problematic_names <- function(message_template, v) {
1457+
res <- character(0)
1458+
for (e in v){
1459+
matches <- character(0)
1460+
for (pc in problematic_chars) if (grepl(pc, e, fixed = TRUE)) {
1461+
single_char <- substr(pc, 1, 1) # deals with backslash
1462+
matches <- c(matches, single_char)
1463+
}
1464+
if (length(matches)) {
1465+
res <- c(res, sprintf(message_template, e, paste(sprintf("'<b>%s</b>'", matches), collapse = ", ")))
1466+
}
1467+
}
1468+
res <- paste(res, collapse = "<br>")
1469+
return(res)
1470+
}
1471+
1472+
dataset_list_names <- names(afmm[["data"]])
1473+
CM$assert(
1474+
container = err,
1475+
cond = !any(grepl(problematic_chars_regexp, dataset_list_names)),
1476+
msg = report_problematic_names(
1477+
paste('The dataset list name "<b>%s</b>" contains characters (%s) incompatible with the review functionality.',
1478+
"That string would be used as part of review-related folder names and those characters could cause problems",
1479+
'<a href="https://en.wikipedia.org/wiki/Filename#Problematic_characters" target="_blank">(details)<a>.',
1480+
"Please, exclude them."),
1481+
dataset_list_names)
1482+
)
1483+
dataset_names <- names(review[["datasets"]])
1484+
CM$assert(
1485+
container = err,
1486+
cond = !any(grepl(problematic_chars_regexp, dataset_names)),
1487+
msg = report_problematic_names(
1488+
paste('The dataset name "<b>%s</b>" contains characters (%s) incompatible with the review functionality.',
1489+
"That string would be used as part of review-related file names and those characters could cause problems",
1490+
'<a href="https://en.wikipedia.org/wiki/Filename#Problematic_characters" target="_blank">(details)<a>.',
1491+
"Please, exclude them."),
1492+
dataset_names)
1493+
)
14461494
}

man/check_review_parameter.Rd

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-review.R

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,3 +237,23 @@ test_that("REV_compute_status preserves expected behavior", {
237237
expect_equal(res, factor(c("Conflict", "Pending", "Pending"), levels = res_levels))
238238
})
239239

240+
test_that("check_review_parameter warns against problematic characters in dataset names", {
241+
mock_afmm = list(data = list(`dataset_list/not_allowed` = NULL))
242+
review <- list(
243+
datasets = list("not/allowed" = list(id_vars = c("USUBJID", "AESEQ"),
244+
tracked_vars = c("TRACKED_1", "TRACKED_2", "TRACKED_3"))),
245+
choices = c("choiceA", "choiceB"), roles = c("roleA", "roleB")
246+
)
247+
248+
err <- CM$container()
249+
check_review_parameter(
250+
afmm = mock_afmm,
251+
datasets = list(),
252+
dataset_names = c("not/allowed"),
253+
review = review,
254+
err = err
255+
)
256+
257+
expect_true(any(grepl("Problematic_characters", err[["messages"]])))
258+
})
259+

0 commit comments

Comments
 (0)