Skip to content

Commit

Permalink
Sys.setlocale returns the updated locale, not the previous one (#1035)
Browse files Browse the repository at this point in the history
  • Loading branch information
aronatkins committed Jan 17, 2024
1 parent ec827b4 commit 2eae8dd
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# rsconnect (development version)

* Restore the `LC_TIME` locale after computing an RFC-2616 date. (#1035)

# rsconnect 1.2.0

* Addressed a number of republishing and collaboration issues where the
Expand Down
5 changes: 3 additions & 2 deletions R/http.R
Original file line number Diff line number Diff line change
Expand Up @@ -518,10 +518,11 @@ signatureHeaders <- function(authInfo, method, path, file = NULL) {

rfc2616Date <- function(time = Sys.time()) {
# set locale to POSIX/C to ensure ASCII date
old <- Sys.setlocale("LC_TIME", "C")
old <- Sys.getlocale("LC_TIME")
Sys.setlocale("LC_TIME", "C")
defer(Sys.setlocale("LC_TIME", old))

strftime(Sys.time(), "%a, %d %b %Y %H:%M:%S GMT", tz = "GMT")
strftime(time, "%a, %d %b %Y %H:%M:%S GMT", tz = "GMT")
}

# Helpers -----------------------------------------------------------------
Expand Down
9 changes: 9 additions & 0 deletions tests/testthat/test-http.R
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,12 @@ test_that("parse and build are symmetric", {
round_trip("https://google.com:80/a/b")
round_trip("https://google.com:80/a/b/")
})

test_that("rcf2616 returns an ASCII date and undoes changes to the locale", {
old <- Sys.getlocale("LC_TIME")
defer(Sys.setlocale("LC_TIME", old))

date <- rfc2616Date(time = as.POSIXct("2024-01-01 01:02:03", tz = "EST"))
expect_equal(date, "Mon, 01 Jan 2024 06:02:03 GMT")
expect_equal(Sys.getlocale("LC_TIME"), old)
})

0 comments on commit 2eae8dd

Please sign in to comment.