Skip to content

Commit

Permalink
Prevent parseUTF8 from overwriting srcfile attribute (#930)
Browse files Browse the repository at this point in the history
  • Loading branch information
meztez authored Nov 20, 2023
1 parent 58e54d3 commit 25117ed
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# plumber (development version)

* Fix #916, related to `parseUTF8` return value attribute `srcfile` on Windows. (#930)

# plumber 1.2.1

Expand Down
4 changes: 2 additions & 2 deletions R/utf8.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ parseUTF8 <- function(file) {
file <- tempfile(); on.exit(unlink(file), add = TRUE)
writeLines(lines, file)
}

# keep the source locations within the file while parsing
exprs <- try(parse(file, keep.source = TRUE, srcfile = src, encoding = enc))
exprs <- try(parse(file, keep.source = FALSE, srcfile = src, encoding = enc))
if (inherits(exprs, "try-error")) {
stop("Error sourcing ", file)
}
Expand Down
4 changes: 4 additions & 0 deletions tests/testthat/test-utf8.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
test_that("parseUTF8 has same srcfile attribute as file arg input", {
filename <- test_path("files/plumber.R")
expect_equal(attr(parseUTF8(filename), "srcfile")$filename, filename)
})

0 comments on commit 25117ed

Please sign in to comment.