Skip to content

Commit

Permalink
escape if pivot cacheField is string (#650)
Browse files Browse the repository at this point in the history
  • Loading branch information
JanMarvin committed Jun 13, 2023
1 parent 813a9fb commit eecb6a8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/helperFunctions.R
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,7 @@ cacheFields <- function(wbdata, filter, rows, cols, data) {
} else {

if (is_char) {
xml_node_create("s", xml_attributes = c(v = uni))
xml_node_create("s", xml_attributes = c(v = uni), escapes = TRUE)
} else if (is_date) {
xml_node_create("d", xml_attributes = c(v = uni))
} else {
Expand Down
19 changes: 19 additions & 0 deletions tests/testthat/test-write.R
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,25 @@ test_that("writing pivot tables works", {

})

test_that("writing pivot with escaped characters works", {

example_df <- data.frame(
location = c("London", "NYC", "NYC", "Berlin", "Madrid", "London", "Austin & Dallas"),
amount = c(7, 5, 3, 2.5, 6, 1, 17)
)

wb <- wb_workbook() %>% wb_add_worksheet() %>% wb_add_data(x = example_df)
df <- wb_data(wb)
wb <- wb %>% wb_add_pivot_table(df, dims = "A3", rows = "location", data = "amount")

cf <- xml_node(wb$pivotDefinitions, "pivotCacheDefinition", "cacheFields", "cacheField")[1]

exp <- "<s v=\"Austin &amp; Dallas\"/>"
got <- xml_node(cf, "cacheField", "sharedItems", "s")[5]
expect_equal(exp, got)

})

test_that("writing na.strings = NULL works", {

# write na.strings = na_strings()
Expand Down

0 comments on commit eecb6a8

Please sign in to comment.