Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: objr
Title: Wrapper for Objective APIs
Version: 0.2.0.9000
Version: 0.2.1
Authors@R: c(
person("Scottish Government", , , "statistics.enquiries@gov.scot", role = "cph"),
person("Alice", "Hannah", , "alice.hannah@gov.scot", role = c("aut", "cre"))
Expand Down
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# objr (development version)
# objr 0.2.1

* Fix bug when downloaded files have MIME-encoded syntax (#72).

# objr 0.2.0

Expand Down
5 changes: 5 additions & 0 deletions R/utils_download-upload.R
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,7 @@ file_name_from_header <- function(response,
cont_disp,
m = regexpr("(?<=filename=\\\").*(?=\\\")", cont_disp, perl = TRUE)
) %>%
decode_mime() %>%
utils::URLdecode()

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

}

decode_mime <- function(string) {
gsub("(^=\\?UTF-8\\?Q\\?)|(\\?=$)", replacement = "", string)
}
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ objr (pronounced "ob-jar") aims to provide a convenient method of interacting wi
## Installation

If you are working within the Scottish Government network, you can
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).
install objr in the same way as with other R packages.

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.
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.

``` r
remotes::install_github(
Expand Down
20 changes: 20 additions & 0 deletions tests/testthat/test-utils_download-upload.R
Original file line number Diff line number Diff line change
Expand Up @@ -280,4 +280,24 @@ test_that("Correct value returned", {
),
"ayrshire & arran.csv"
)

expect_equal(
file_name_from_header(
httr2::response(
headers = list(
`Content-Disposition` =
"filename=\"=?UTF-8?Q?ayrshire%20%26%20arran.csv?=\""
)
)
),
"ayrshire & arran.csv"
)
})


# decode_mime ----

test_that("Correct value returned", {
expect_equal(decode_mime("test.csv"), "test.csv")
expect_equal(decode_mime("=?UTF-8?Q?test.csv?="), "test.csv")
})