Skip to content

Commit

Permalink
Enforce use of UTF-8 encoding when writing strings.
Browse files Browse the repository at this point in the history
This avoids incorrect saving of multi-byte characters in non-UTF-8 locales.
  • Loading branch information
LTLA committed Sep 22, 2024
1 parent 7509a17 commit ceb265e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: alabaster.base
Title: Save Bioconductor Objects To File
Version: 1.5.8
Date: 2024-09-13
Version: 1.5.9
Date: 2024-09-22
Authors@R: person("Aaron", "Lun", role=c("aut", "cre"), email="[email protected]")
License: MIT + file LICENSE
Description:
Expand Down
6 changes: 6 additions & 0 deletions R/hdf5.R
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,9 @@ h5_create_vector <- function(handle, name, len, type, compress=6, chunks=NULL, s
#' @export
h5_write_vector <- function(handle, name, x, type=NULL, compress=6, chunks=NULL, scalar=FALSE, emit=FALSE) {
if (is.null(type)) {
if (is.character(x)) {
x <- enc2utf8(x) # avoid mis-encoding multi-byte characters from Latin-1.
}
type <- .choose_type(x)
}

Expand All @@ -101,6 +104,9 @@ h5_write_vector <- function(handle, name, x, type=NULL, compress=6, chunks=NULL,
#' @export
h5_write_attribute <- function(handle, name, x, type=NULL, scalar=FALSE) {
if (is.null(type)) {
if (is.character(x)) {
x <- enc2utf8(x) # avoid mis-encoding multi-byte characters from Latin-1.
}
type <- .choose_type(x)
}

Expand Down
1 change: 1 addition & 0 deletions R/transformVectorForHdf5.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ transformVectorForHdf5 <- function(x, .version=3) {
}

} else if (is.character(x)) {
x <- enc2utf8(x) # avoid mis-encoding multi-byte characters from Latin-1.
if (anyNA(x)) {
placeholder <- chooseMissingPlaceholderForHdf5(x)
x[is.na(x)] <- placeholder
Expand Down

0 comments on commit ceb265e

Please sign in to comment.