Skip to content

Commit

Permalink
Merge pull request #979 from rstudio/handle-description-encoding
Browse files Browse the repository at this point in the history
handle non-utf8 description encodings
  • Loading branch information
mslynch authored Aug 28, 2023
2 parents 2eda945 + 2098c30 commit 92d35f8
Show file tree
Hide file tree
Showing 14 changed files with 91 additions and 2 deletions.
4 changes: 2 additions & 2 deletions R/bundlePackage.R
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,6 @@ availablePackages <- function(repos) {
}

package_record <- function(name, lib_dir = NULL) {
path <- system.file("DESCRIPTION", package = name, lib.loc = lib_dir)
as.list(as.data.frame(read.dcf(path)))
record <- packageDescription(name, lib.loc = lib_dir, encoding = "UTF-8")
unclass(record)
}
10 changes: 10 additions & 0 deletions tests/testthat/packages/latin1package/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Package: latin1package
Type: Package
Title: Provides some funky characters.
Version: 0.1.0
Author: Jens Fr�hling
Maintainer: Jens Fr�hling <[email protected]>
Description: a test package
License: GPL-2
Encoding: latin1
LazyData: true
1 change: 1 addition & 0 deletions tests/testthat/packages/latin1package/NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exportPattern("^[[:alpha:]]+")
3 changes: 3 additions & 0 deletions tests/testthat/packages/latin1package/R/hello.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
hello <- function() {
print("Hello, world!")
}
12 changes: 12 additions & 0 deletions tests/testthat/packages/latin1package/man/hello.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
\name{hello}
\alias{hello}
\title{Hello, World!}
\usage{
hello()
}
\description{
Prints 'Hello, world!'.
}
\examples{
hello()
}
10 changes: 10 additions & 0 deletions tests/testthat/packages/utf8package/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Package: utf8package
Type: Package
Title: Provides some funky characters.
Version: 0.1.0
Author: Jens Fröhling
Maintainer: Jens Fröhling <[email protected]>
Description: a test package
License: GPL-2
Encoding: UTF-8
LazyData: true
1 change: 1 addition & 0 deletions tests/testthat/packages/utf8package/NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exportPattern("^[[:alpha:]]+")
3 changes: 3 additions & 0 deletions tests/testthat/packages/utf8package/R/hello.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
hello <- function() {
print("Hello, world!")
}
12 changes: 12 additions & 0 deletions tests/testthat/packages/utf8package/man/hello.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
\name{hello}
\alias{hello}
\title{Hello, World!}
\usage{
hello()
}
\description{
Prints 'Hello, world!'.
}
\examples{
hello()
}
10 changes: 10 additions & 0 deletions tests/testthat/packages/windows1251package/DESCRIPTION
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Package: windows1251package
Type: Package
Title: Provides some funky characters.
Version: 0.1.0
Author: ������ ����
Maintainer: ������ ���� <[email protected]>
Description: a test package
License: GPL-2
Encoding: Windows-1251
LazyData: true
1 change: 1 addition & 0 deletions tests/testthat/packages/windows1251package/NAMESPACE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
exportPattern("^[[:alpha:]]+")
3 changes: 3 additions & 0 deletions tests/testthat/packages/windows1251package/R/hello.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
hello <- function() {
print("Hello, world!")
}
12 changes: 12 additions & 0 deletions tests/testthat/packages/windows1251package/man/hello.Rd
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
\name{hello}
\alias{hello}
\title{Hello, World!}
\usage{
hello()
}
\description{
Prints 'Hello, world!'.
}
\examples{
hello()
}
11 changes: 11 additions & 0 deletions tests/testthat/test-bundlePackage.R
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,14 @@ test_that("usePackrat prefers the environment variable over the option", {
withr::local_options(rsconnect.packrat = TRUE)
expect_false(usePackrat())
})

test_that("package_record works", {
latin1Record <- package_record("latin1package", lib_dir = test_path("packages"))
expect_equal(latin1Record$Author, "Jens Fröhling")

utf8Record <- package_record("utf8package", lib_dir = test_path("packages"))
expect_equal(utf8Record$Author, "Jens Fröhling")

windows1251Record <- package_record("windows1251package", lib_dir = test_path("packages"))
expect_equal(windows1251Record$Author, "Сергей Брин")
})

0 comments on commit 92d35f8

Please sign in to comment.