Skip to content

Commit 97f4378

Browse files
authored
Merge pull request #44 from ScotGovAnalysis/decode-url
Decode file names downloaded by `download_file()`
2 parents c0c0973 + a1e0836 commit 97f4378

File tree

4 files changed

+14
-7
lines changed

4 files changed

+14
-7
lines changed

NEWS.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# objr (development version)
22

3+
* `download_file()` now writes files with percent-decoded names
4+
(e.g. `file%20name.csv` is now `file name.csv`) (#34).
5+
36
* Fixed an issue where temporary files sometimes persisted after running
47
`download_file()` or `read_file()` (#39).
58

R/utils_download-upload.R

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,12 @@ file_name_from_header <- function(response,
201201

202202
cont_disp <- httr2::resp_header(response, "Content-Disposition")
203203

204-
file_name <- regmatches(
205-
cont_disp,
206-
m = regexpr("(?<=filename=\\\").*(?=\\\")", cont_disp, perl = TRUE)
207-
)
204+
file_name <-
205+
regmatches(
206+
cont_disp,
207+
m = regexpr("(?<=filename=\\\").*(?=\\\")", cont_disp, perl = TRUE)
208+
) %>%
209+
utils::URLdecode()
208210

209211
if (length(file_name) == 0) {
210212
cli::cli_abort(

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
<!-- badges: end -->
1010

11-
objr aims to provide a convenient method of interacting with [Objective Connect](https://secure.objectiveconnect.co.uk) using R, making use of the [Objective Connect API](https://secure.objectiveconnect.co.uk/publicapi/1/swagger-ui/index.html).
11+
objr (pronounced "ob-jar") aims to provide a convenient method of interacting with [Objective Connect](https://secure.objectiveconnect.co.uk) using R, making use of the [Objective Connect API](https://secure.objectiveconnect.co.uk/publicapi/1/swagger-ui/index.html).
1212

1313
## Installation
1414

tests/testthat/test-utils_download-upload.R

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,9 +252,11 @@ test_that("Correct value returned", {
252252
expect_equal(
253253
file_name_from_header(
254254
httr2::response(
255-
headers = list(`Content-Disposition` = "filename=\"new_name.csv\"")
255+
headers = list(
256+
`Content-Disposition` = "filename=\"ayrshire%20%26%20arran.csv\""
257+
)
256258
)
257259
),
258-
"new_name.csv"
260+
"ayrshire & arran.csv"
259261
)
260262
})

0 commit comments

Comments
 (0)