Skip to content

Commit 56c304c

Browse files
authored
Merge pull request #73 from ScotGovAnalysis/mime-bug
Decode MIME strings in downloaded file names
2 parents 40be2d3 + 1bc6b8a commit 56c304c

File tree

5 files changed

+32
-4
lines changed

5 files changed

+32
-4
lines changed

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Package: objr
22
Title: Wrapper for Objective APIs
3-
Version: 0.2.0.9000
3+
Version: 0.2.1
44
Authors@R: c(
55
person("Scottish Government", , , "[email protected]", role = "cph"),
66
person("Alice", "Hannah", , "[email protected]", role = c("aut", "cre"))

NEWS.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
# objr (development version)
1+
# objr 0.2.1
2+
3+
* Fix bug when downloaded files have MIME-encoded syntax (#72).
24

35
# objr 0.2.0
46

R/utils_download-upload.R

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,7 @@ file_name_from_header <- function(response,
236236
cont_disp,
237237
m = regexpr("(?<=filename=\\\").*(?=\\\")", cont_disp, perl = TRUE)
238238
) %>%
239+
decode_mime() %>%
239240
utils::URLdecode()
240241

241242
if (length(file_name) == 0) {
@@ -251,3 +252,7 @@ file_name_from_header <- function(response,
251252
file_name
252253

253254
}
255+
256+
decode_mime <- function(string) {
257+
gsub("(^=\\?UTF-8\\?Q\\?)|(\\?=$)", replacement = "", string)
258+
}

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ objr (pronounced "ob-jar") aims to provide a convenient method of interacting wi
1313
## Installation
1414

1515
If you are working within the Scottish Government network, you can
16-
install objr in the same way as with other R packages. The easiest way to do this is by using the [pkginstaller](https://github.com/ScotGovAnalysis/pkginstaller/tree/main) add-in. Further guidance is available on [eRDM](https://erdm.scotland.gov.uk:8443/documents/A42404229/details).
16+
install objr in the same way as with other R packages.
1717

18-
Alternatively, objr can be installed directly from GitHub. Note that this method requires the remotes package and may not work from within the Scottish Government network.
18+
Alternatively, objr can be installed directly from GitHub.
19+
Note that this method requires the remotes package and may not work from within the Scottish Government network.
1920

2021
``` r
2122
remotes::install_github(

tests/testthat/test-utils_download-upload.R

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,4 +280,24 @@ test_that("Correct value returned", {
280280
),
281281
"ayrshire & arran.csv"
282282
)
283+
284+
expect_equal(
285+
file_name_from_header(
286+
httr2::response(
287+
headers = list(
288+
`Content-Disposition` =
289+
"filename=\"=?UTF-8?Q?ayrshire%20%26%20arran.csv?=\""
290+
)
291+
)
292+
),
293+
"ayrshire & arran.csv"
294+
)
295+
})
296+
297+
298+
# decode_mime ----
299+
300+
test_that("Correct value returned", {
301+
expect_equal(decode_mime("test.csv"), "test.csv")
302+
expect_equal(decode_mime("=?UTF-8?Q?test.csv?="), "test.csv")
283303
})

0 commit comments

Comments
 (0)