Skip to content

Commit

Permalink
Translate names to native encoding before creating data mask
Browse files Browse the repository at this point in the history
  • Loading branch information
lionel- committed May 29, 2018
1 parent b629d63 commit 6c0adec
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/lib/vec-chr.h
Expand Up @@ -84,7 +84,7 @@ static inline bool r_is_string(sexp* x, const char* string) {
}

static inline sexp* r_str_as_symbol(sexp* str) {
return r_sym(CHAR(str));
return r_sym(Rf_translateChar(str));
}

static inline bool r_str_is_name(sexp* str) {
Expand Down
18 changes: 18 additions & 0 deletions tests/testthat/test-eval-tidy.R
Expand Up @@ -313,3 +313,21 @@ test_that("inner formulas are evaluated in the current frame", {
envs <- eval_tidy(quo)
expect_identical(envs$f_env, envs$env)
})

test_that("names are translated to native when creating data mask", {
with_latin1_locale({
str_utf8 <- "\u00fc"
str_native <- enc2native(str_utf8)

d <- set_names(list("value"), str_utf8)
s <- sym(str_native)
expect_identical(eval_tidy(s, data = d), "value")

foreign_utf8 <- "\u5FCD"
foreign_native <- enc2native(foreign_utf8)

d <- setNames(list("value"), foreign_utf8)
s <- sym(foreign_native)
expect_identical(eval_tidy(s, data = d), "value")
})
})

0 comments on commit 6c0adec

Please sign in to comment.