Skip to content

Commit 7c5594a

Browse files
authored
Search for JS() calls recursively only in explicit lists and data.frames (#467)
* Use type-safe name assignment Names are characters, explicitly cast indices to characters * Recurse over explicit lists and data.frames Avoids recursion of list-like objects that aren't actually lists. Recursion over data.frames is uncommon but was previously supported and can, in theory, contain `JS()` calls in list columns. * docs: Add news item
1 parent d31dd27 commit 7c5594a

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

NEWS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# htmlwidgets (development version)
22

3+
### Potentially breaking changes
4+
5+
* Closed #466: htmlwidgets no longer recurses into list-like objects when searching for JavaScript strings wrapped in `JS()`, unless the object has the class `"list"` or `"data.frame"`. This stops htmlwidgets from (possibly infinitely) recursively searching objects that are not actually recursive. Widget authors who relied on the previous behavior should ensure that their widget's `JS()` calls are wrapped in objects that have the class `"list"` or `"data.frame"`. (#467)
6+
37

48
# htmlwidgets 1.6.2
59

R/utils.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,11 @@ JSEvals <- function(list) {
161161
#' @noRd
162162
#' @keywords internal
163163
shouldEval <- function(options) {
164-
if (is.list(options)) {
164+
if (inherits(options, c("list", "data.frame"))) {
165165
if ((n <- length(options)) == 0) return(FALSE)
166166
# use numeric indices as names (remember JS indexes from 0, hence -1 here)
167167
if (is.null(names(options)))
168-
names(options) <- seq_len(n) - 1L
168+
names(options) <- as.character(seq_len(n) - 1L)
169169
# Escape '\' and '.' by prefixing them with '\'. This allows us to tell the
170170
# difference between periods as separators and periods that are part of the
171171
# name itself.

0 commit comments

Comments
 (0)