Skip to content

Commit

Permalink
response$send_file() and root = "/" fix on Windows
Browse files Browse the repository at this point in the history
We cannot just use `file.path()` because if prepends the
`/` in front of the device letter: `/c:/foo...`.
  • Loading branch information
gaborcsardi committed Nov 7, 2022
1 parent a116b79 commit 31fc398
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# webfakes (development version)

* `response$send_file()` now handles `root = "/"` and absolute paths
better on Windows.

* `new_app_process()` and `local_app_process()` are now faster,
because the app object they need to copy to the subprocess is smaller.

Expand Down
9 changes: 8 additions & 1 deletion R/response.R
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,14 @@ new_response <- function(app, req) {
}
}

self$send(read_bin(normalizePath(file.path(root, path))))
if (root == "/" && .Platform$OS.type == "windows" &&
grepl("^[a-zA-Z]:", path)) {
abs_path <- path
} else {
abs_path <- file.path(root, path)
}

self$send(read_bin(normalizePath(abs_path)))
},

send_status = function(status) {
Expand Down

0 comments on commit 31fc398

Please sign in to comment.