Skip to content

Commit

Permalink
[fmt_txt] escape xml (#757)
Browse files Browse the repository at this point in the history
* [fmt_txt] escape xml

fixes pteridin/flexlsx#2 (comment)

* redoc
  • Loading branch information
JanMarvin committed Aug 23, 2023
1 parent fc90829 commit ff1af50
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion man/wb_add_formula.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions tests/testthat/test-utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -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 <- "<r><rPr><b/></rPr><t>0 &lt; 1</t></r>"
got <- unclass(txt)
expect_equal(exp, got)

})

0 comments on commit ff1af50

Please sign in to comment.