-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow non-standard datanames in filter data (#622)
# Pull Request Fixes insightsengineering/teal#1366 Related: - insightsengineering/teal#1382 - #622 - insightsengineering/teal.data#340 ### Changes description - Removed assertion on datanames that start with alphabetic character - [x] Fix problem with JS namespace in filter panel - [x] Fix crash when filtering using MAE (both SE and Matrix) - [x ] ~Fix upload of snapshot file that is not compatible~ - [x] Ignore datanames that contain functions, language, expression (and other non-data objects) - insightsengineering/teal#1352 --------- Signed-off-by: André Veríssimo <[email protected]> Co-authored-by: Dawid Kałędkowski <[email protected]>
- Loading branch information
1 parent
aa05f7f
commit dc9f82b
Showing
11 changed files
with
191 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,96 @@ | ||
# check_simple_name ---- | ||
test_that("check_simple_name behaves as expected", { | ||
testthat::expect_silent(check_simple_name("aas2df")) | ||
testthat::expect_silent(check_simple_name("ADSL")) | ||
testthat::expect_silent(check_simple_name("ADSLmodified")) | ||
testthat::expect_silent(check_simple_name("a1")) | ||
testthat::expect_silent(check_simple_name("ADSL_modified")) | ||
testthat::expect_silent(check_simple_name("ADSL_filtered")) | ||
testthat::expect_silent(check_simple_name("FILTERED_ADSL")) | ||
testthat::expect_silent(check_simple_name("FILTERED")) | ||
testthat::expect_silent(check_simple_name("ADSLFILTERED")) | ||
testthat::expect_silent(check_simple_name("a_1_2_b_")) | ||
|
||
testthat::expect_error(check_simple_name("1a"), "name '.+' must only contain alphanumeric characters") | ||
testthat::expect_error(check_simple_name("ADSL.modified"), "name '.+' must only contain alphanumeric characters") | ||
testthat::expect_error(check_simple_name("a1..."), "name '.+' must only contain alphanumeric characters") | ||
testthat::expect_error(check_simple_name("a a"), "name '.+' must only contain alphanumeric characters") | ||
testthat::expect_error(check_simple_name("_A_b"), "name '.+' must only contain alphanumeric characters") | ||
}) | ||
|
||
# make_c_call ---- | ||
testthat::test_that("make_c_call", { | ||
testthat::expect_identical(make_c_call(1:3), quote(c(1L, 2L, 3L))) | ||
testthat::expect_identical(make_c_call(1), 1) | ||
}) | ||
|
||
# sanitize_id ---- | ||
testthat::describe("sanitize_id", { | ||
testthat::it("should replace dots with `_` when id is otherwise valid", { | ||
id <- "a.b" | ||
ns <- teal.slice:::NS("app") | ||
testthat::expect_identical( | ||
ns(id), | ||
paste0("app-h", substr(rlang::hash(id), 1, 4), "_a_b") | ||
) | ||
}) | ||
|
||
testthat::it("should take vector input", { | ||
id <- c("a.b", "a", "b", " c") | ||
ns <- teal.slice:::NS("app") | ||
testthat::expect_identical( | ||
ns(id), | ||
c( | ||
paste0("app-h", substr(rlang::hash(id[1]), 1, 4), "_a_b"), | ||
"app-a", | ||
"app-b", | ||
paste0("app-h", substr(rlang::hash(id[4]), 1, 4), "__c") | ||
) | ||
) | ||
}) | ||
|
||
testthat::it("should allow for integer input", { | ||
id <- c(1L, 2L, 3L) | ||
ns <- teal.slice:::NS("app") | ||
testthat::expect_identical( | ||
ns(id), | ||
c("app-1", "app-2", "app-3") | ||
) | ||
}) | ||
|
||
testthat::it("should replace non-ASCII characters in middle of id with `_`", { | ||
id <- "a$b" | ||
ns <- teal.slice:::NS("app") | ||
testthat::expect_identical( | ||
ns(id), | ||
paste0("app-h", substr(rlang::hash(id), 1, 4), "_a_b") | ||
) | ||
}) | ||
|
||
# Test using moduleServer to access the sanitized id | ||
testthat::it("should replace non-ASCII characters in the start/end of id with `_`", { | ||
id <- "%a bad symbol$" | ||
id2 <- "a&b#" | ||
id_from_module <- shiny::withReactiveDomain( | ||
MockShinySession$new(), | ||
teal.slice:::moduleServer(id, function(input, output, session) session$ns("a_good_name")) | ||
) | ||
|
||
testthat::expect_identical( | ||
id_from_module, | ||
paste0("h", substr(rlang::hash(id), 1, 4), "__a_bad_symbol_-a_good_name") | ||
) | ||
}) | ||
|
||
testthat::it("should replace all quotes characters with `_`", { | ||
id <- " a.b.c\"d`e'j" | ||
testthat::expect_identical( | ||
teal.slice:::NS("app", id), | ||
paste0("app-h", substr(rlang::hash(id), 1, 4), "__a_b_c_d_e_j") | ||
) | ||
}) | ||
|
||
testthat::it("should replace all escape characters from JQuery selectors", { | ||
forbidden <- " !\"#$%&'()*+,./:;<=>?@[\\]^`{|}~]" | ||
testthat::expect_identical( | ||
teal.slice:::NS("app", forbidden), | ||
paste0( | ||
"app-h", | ||
substr(rlang::hash(forbidden), 1, 4), | ||
paste(rep("_", nchar(forbidden) + 1), collapse = "") | ||
) | ||
) | ||
}) | ||
|
||
testthat::it("should replace UTF characters outside the allowed range", { | ||
id <- "\U41\U05E\U30\U5F\U7A\U1F4AA" # "A:circumflex_accent:0_z:flexed_biceps: | ||
testthat::expect_identical( | ||
teal.slice:::NS("app", id), | ||
paste0( | ||
"app-h", | ||
substr(rlang::hash(id), 1, 4), | ||
"_A_0_z_" | ||
) | ||
) | ||
}) | ||
}) |