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: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

* Do not drop the `glue` class when subsetting (#66).

* Fix `glue()` and `collapse()` always return UTF-8 encoded strings (#81, @dpprdan)

# glue 1.2.0

* The implementation has been tweaked to be slightly faster in most cases.
Expand Down
2 changes: 1 addition & 1 deletion R/glue.R
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ as_glue.glue <- function(x, ...) {
#' @export
as_glue.character <- function(x, ...) {
class(x) <- c("glue", "character")
x
enc2utf8(x)
}

#' @export
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/test-glue.R
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ test_that("glue always returns UTF-8 encoded strings regardless of input encodin

expect_identical(x_out, glue(x))
expect_identical(x_out, glue("{x}"))
expect_equal(Encoding(glue(x)), "UTF-8")
expect_equal(Encoding(glue("{x}")), "UTF-8")

y <- "p\u00E4o"
Encoding(y) <- "UTF-8"
Expand All @@ -241,11 +243,17 @@ test_that("glue always returns UTF-8 encoded strings regardless of input encodin

expect_identical(y_out, glue(y))
expect_identical(y_out, glue("{y}"))
expect_equal(Encoding(glue(y)), "UTF-8")
expect_equal(Encoding(glue("{y}")), "UTF-8")

xy_out <- as_glue(paste0(x_out, y_out))

expect_identical(xy_out, glue(x, y))
expect_identical(xy_out, glue("{x}{y}"))
expect_equal(Encoding(glue(x, y)), "UTF-8")
expect_equal(Encoding(glue("{x}{y}")), "UTF-8")

expect_equal(Encoding(collapse(x)), "UTF-8")
})

test_that("glue always returns NA_character_ if given any NA input and `.na` == NULL", {
Expand Down