From ff1af5089fd207be3b91c3a1b0f4106706ada6ed Mon Sep 17 00:00:00 2001 From: Jan Marvin Garbuszus Date: Wed, 23 Aug 2023 20:16:53 +0200 Subject: [PATCH] [fmt_txt] escape xml (#757) * [fmt_txt] escape xml fixes https://github.com/pteridin/flexlsx/issues/2#issuecomment-1689861438 * redoc --- R/utils.R | 2 +- man/wb_add_formula.Rd | 1 - tests/testthat/test-utils.R | 9 +++++++++ 3 files changed, 10 insertions(+), 2 deletions(-) diff --git a/R/utils.R b/R/utils.R index f773622f9..75f6e9dfd 100644 --- a/R/utils.R +++ b/R/utils.R @@ -930,7 +930,7 @@ fmt_txt <- function( } xml_t_attr <- if (grepl("(^\\s+)|(\\s+$)", x)) c("xml:space" = "preserve") else NULL - xml_t <- xml_node_create("t", xml_children = x, xml_attributes = xml_t_attr) + xml_t <- xml_node_create("t", xml_children = replace_legal_chars(x), xml_attributes = xml_t_attr) xml_rpr <- xml_node_create( "rPr", diff --git a/man/wb_add_formula.Rd b/man/wb_add_formula.Rd index a0db878dc..2a1545cd3 100644 --- a/man/wb_add_formula.Rd +++ b/man/wb_add_formula.Rd @@ -61,7 +61,6 @@ The examples below show a small list of possible formulas: \item MAX(B2:B4) \item ... } - } \examples{ wb <- wb_workbook()$add_worksheet() diff --git a/tests/testthat/test-utils.R b/tests/testthat/test-utils.R index a7ffd2cef..0eb564de5 100644 --- a/tests/testthat/test-utils.R +++ b/tests/testthat/test-utils.R @@ -399,4 +399,13 @@ test_that("fmt_txt works", { got <- as.character(txt) expect_equal(exp, got) + txt <- fmt_txt("0 < 1", bold = TRUE) + exp <- "0 < 1" + got <- as.character(txt) + expect_equal(exp, got) + + exp <- "0 < 1" + got <- unclass(txt) + expect_equal(exp, got) + })