diff --git a/NEWS.md b/NEWS.md index cd188a2d..e2ada2a4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,6 @@ # plumber (development version) +* Fix #916, related to `parseUTF8` return value attribute `srcfile` on Windows. (#930) # plumber 1.2.1 diff --git a/R/utf8.R b/R/utf8.R index db8eab00..68be417d 100644 --- a/R/utf8.R +++ b/R/utf8.R @@ -66,13 +66,15 @@ parseUTF8 <- function(file) { # **can** be encoded natively on Windows (might be a bug in base R); we # rewrite the source code in a natively encoded temp file and parse it in this # case (the source reference is still pointed to the original file, though) + keepsource <- TRUE if (isWindows() && enc == 'unknown') { file <- tempfile(); on.exit(unlink(file), add = TRUE) writeLines(lines, file) + keepsource <- FALSE } - + # 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 = keepsource, srcfile = src, encoding = enc)) if (inherits(exprs, "try-error")) { stop("Error sourcing ", file) } diff --git a/tests/testthat/test-utf8.R b/tests/testthat/test-utf8.R new file mode 100644 index 00000000..f3b29a8e --- /dev/null +++ b/tests/testthat/test-utf8.R @@ -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(file), "srcfile")$filename, filename) +})