mirror of
https://github.com/rstudio/shiny.git
synced 2026-04-07 03:00:20 -04:00
Fix edge case with nested choices. Fixes #560
When the set of choices is a list containing a named vector of length 1, choicesWithNames would return the wrong result.
This commit is contained in:
@@ -681,7 +681,7 @@ choicesWithNames <- function(choices) {
|
||||
res <- lapply(obj, function(val) {
|
||||
if (is.list(val))
|
||||
listify(val)
|
||||
else if (length(val) == 1)
|
||||
else if (length(val) == 1 && is.null(names(val)))
|
||||
val
|
||||
else
|
||||
makeNamed(as.list(val))
|
||||
|
||||
@@ -76,6 +76,11 @@ test_that("Choices are correctly assigned names", {
|
||||
choicesWithNames(list(A="a", B="b", C=list("d", "e"))),
|
||||
list(A="a", B="b", C=list(d="d", e="e"))
|
||||
)
|
||||
# List, named, with a named sub-vector of length 1
|
||||
expect_identical(
|
||||
choicesWithNames(list(A="a", B="b", C=c(D="d"))),
|
||||
list(A="a", B="b", C=list(D="d"))
|
||||
)
|
||||
# List, some named, with sublist
|
||||
expect_identical(
|
||||
choicesWithNames(list(A="a", "b", C=list("d", E="e"))),
|
||||
|
||||
Reference in New Issue
Block a user