Skip to content

Commit

Permalink
Fix repr of list with identical(names(l), '')
Browse files Browse the repository at this point in the history
  • Loading branch information
flying-sheep committed Aug 19, 2020
1 parent 83c64b9 commit 9af4e98
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
4 changes: 3 additions & 1 deletion R/repr_list.r
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ repr_list_generic <- function(
escape_fun = identity) {

nms <- names(vec)
if (!is.null(nms)) {
if (identical(nms, '')) {
nms <- NULL
} else if (!is.null(nms)) {
nms <- as.character(sapply(nms, as_name_or_na, USE.NAMES = FALSE)) # adds `` around special chars
nms <- escape_fun(nms)
}
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test_repr_list.r
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,11 @@ test_that('NAs can occur in list names', {
</dl>
')
})

test_that('Lists with empty strings as names work', {
l <- structure(list(1), names = '')
expect_identical(repr_html(l), '<ol>
\t<li>1</li>
</ol>
')
})

0 comments on commit 9af4e98

Please sign in to comment.