Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make sure path is in native encoding #477

Merged
merged 8 commits into from
May 11, 2018
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 2 additions & 1 deletion src/XlsWorkBook.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
inline std::string normalizePath(std::string path) {
Rcpp::Environment baseEnv = Rcpp::Environment::base_env();
Rcpp::Function normalizePath = baseEnv["normalizePath"];
return Rcpp::as<std::string>(normalizePath(path, "/", true));
Rcpp::Function enc2native = baseEnv["enc2native"];
return Rcpp::as<std::string>(enc2native(normalizePath(path, "/", true)));
}

class XlsWorkBook {
Expand Down
15 changes: 15 additions & 0 deletions tests/testthat/test-read-excel.R
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,18 @@ test_that("trim_ws must be a logical", {
"`trim_ws` must be either TRUE or FALSE"
)
})

## https://github.com/tidyverse/readxl/issues/476
test_that("non-ASCII xls filenames can be read", {
skip_on_cran()
## chosen to be non-ASCII but
## [1] representable in Windows-1252 and
## [2] not any of the few differences between Windows-1252 and ISO-8859-1
## a-grave + e-diaeresis + Eth + '.xls'
filename <- "\u00C0\u00CB\u00D0\u002E\u0078\u006C\u0073"
tricky_file <- file.path(tempdir(), filename)
file.copy(test_sheet("mtcars.xls"), tricky_file)
expect_true(file.exists(tricky_file))
on.exit(file.remove(tricky_file))
expect_error_free(read_xls(tricky_file))
})