Skip to content
This repository was archived by the owner on Feb 18, 2024. It is now read-only.

Fix transformation of non-ASCII on Windows - #18

Merged
krlmlr merged 5 commits into
krlmlr:masterfrom
yutannihilation:fix-transformation-on-windows
Feb 2, 2018
Merged

krlmlr merged 5 commits into
krlmlr:masterfrom
yutannihilation:fix-transformation-on-windows

Conversation

@yutannihilation

@yutannihilation yutannihilation commented Jan 24, 2018 •

Copy link
Copy Markdown
Contributor

I believe this fixes r-lib/styler#329.

As described the original issue above, in transform_lines_enc_one(), there is nothing to ensure new_text is in the UTF-8 encoding while write_lines_enc() requires UTF-8.

enc/R/io.R

Lines 109 to 116 in 883df89

text <- try_read_lines_enc(path, file_encoding = file_encoding, ok = ok, skipNul = skipNul)
sep <- detect_sep(path)
tryCatch(
{
new_text <- as.character(fun(text))
if (!isTRUE(identical(unclass(text), unclass(new_text)))) {
if (write_back) {
write_lines_enc(new_text, path, file_encoding = file_encoding, sep = sep)

I don't see any major drawbacks to change as.character() to to_utf8(), but I'm still not sure why as.character() was introduced here. Shouldn't it throw an error when fun() returns non-characters? What cases does it consider about?

@yutannihilation

Copy link
Copy Markdown
Contributor Author

@krlmlr Didn't you forget to change AppVeyor's setting when renamed to enc?

@yutannihilation
yutannihilation force-pushed the fix-transformation-on-windows branch from a119b03 to dccbbee Compare January 24, 2018 00:36
@codecov

codecov Bot commented Jan 24, 2018 •

Copy link
Copy Markdown

Codecov Report

Merging #18 into master will not change coverage.
The diff coverage is 100%.

Impacted file tree graph

@@          Coverage Diff           @@
##           master     #18   +/-   ##
======================================
  Coverage    99.4%   99.4%           
======================================
  Files           8       8           
  Lines         167     167           
======================================
  Hits          166     166           
  Misses          1       1
Impacted Files Coverage Δ
R/io.R 100% <100%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b17f414...91252ba. Read the comment docs.

@yutannihilation

Copy link
Copy Markdown
Contributor Author

I've confirmed the test fails with the current implementation and changing character() to to_utf8() fixes the problem on the forked repo's AppVeyor:

yutannihilation#1

@krlmlr krlmlr left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, I agree that enc should convert to UTF-8 as necessary.

Comment thread tests/testthat/test-transform-lines.R Outdated

test_that("forward-reverse transformation works for latin1", {
# c.f. rlang::mut_latin1_locale()
locale <- if (.Platform$OS.type == "windows") "English_United States.1252" else "en_US.ISO8859-1"

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd rather test this only on Windows, because locale names are inconsistent on other OS.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see.

@krlmlr

krlmlr commented Jan 24, 2018

Copy link
Copy Markdown
Owner

My AppVeyor settings are a mess right now, need to review eventually.

@krlmlr
krlmlr merged commit 76ff3e2 into krlmlr:master Feb 2, 2018
@krlmlr

krlmlr commented Feb 2, 2018

Copy link
Copy Markdown
Owner

Thanks!

krlmlr added a commit that referenced this pull request Feb 3, 2018
- Fix transformation of non-ASCII text on Windows (#18, @yutannihilation).
@yutannihilation
yutannihilation deleted the fix-transformation-on-windows branch April 2, 2018 05:31
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Mar 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

style_file() unexpectedly deletes non-ASCII characters on Windows

2 participants