Skip to content

Commit

Permalink
Fix xml_add_parent segfault
Browse files Browse the repository at this point in the history
  • Loading branch information
alexverse committed Jul 11, 2023
1 parent f6f0ceb commit 1903cba
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion R/xml_modify.R
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ xml_add_parent <- function(.x, .value, ...) {

#' @export
xml_add_parent.xml_node <- function(.x, .value, ...) {
new_parent <- xml_replace(.x, .value = .value, ..., .copy = FALSE)
new_parent <- xml_replace(.x, .value = .value, ..., .copy = TRUE)
node <- xml_add_child(new_parent, .value = .x, .copy = FALSE)

invisible(node)
Expand Down
11 changes: 11 additions & 0 deletions tests/testthat/test-modify-xml.R
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,17 @@ test_that("xml_add_parent works with xml_missing input", {
expect_equal(xml_name(xml_children(y)), c("em", "em"))
})

test_that("xml_add_parent not generating segfault during iteration", {
add_parent <- function() {
fruits <- read_xml("<fruits>
<apple color='red'></apple>
</fruits>")
xml_add_parent(fruits, read_xml("<food></food>"))
}

expect_no_error(for(i in 1:100) add_parent())
})

test_that("xml_new_document adds a default character encoding", {

x <- read_xml("<root>\u00E1\u00FC\u00EE</root>")
Expand Down

0 comments on commit 1903cba

Please sign in to comment.