Skip to content

mark R strings in RPC methods as UTF-8 - #8448

Merged
kevinushey merged 3 commits into
v1.4-juliet-rosefrom
bugfix/r-json-rpc-utf8
Dec 7, 2020
Merged

kevinushey merged 3 commits into
v1.4-juliet-rosefrom
bugfix/r-json-rpc-utf8

Conversation

@kevinushey

Copy link
Copy Markdown
Collaborator

Intent

Whenever an RPC method is invoked, it's normally done with JSON data received from the client. Any such strings in that JSON are always UTF-8 encoded. However, when the associated R string is created from that JSON string, we were not marking the encoding. Hence, we ended up with data that was UTF-8 encoded, but interpreted as though it were in the native encoding.

This causes issues of this form on Windows:

#8435 (comment)

A way to convince yourself is with something like the following:

 # take a UTF-8 string ...
> string <- enc2utf8("crème brûlée")
> 
> # but pretend it is latin1 encoded
> Encoding(string) <- "latin1"
> 
> string
[1] "crème brûlée"

And this is exactly the kind of mojibake seen in #8435 (comment).

Approach

Use the associated UTF-8 APIs in RFunction when adding strings from JSON.

QA Notes

On a Windows account with the name Crème Brûlée, confirm that you can create a new R package project.

Closes #8435.
Closes #8445.

@jmcphers

Copy link
Copy Markdown
Member

This seems like a good idea, but an encoding-related change this deep in the RPC mechanism seems like it wants more runway than we have. Do we absolutely need this for 1.4? (Neither of those bugs looks like a regression at first blush.)

@kevinushey

Copy link
Copy Markdown
Collaborator Author

If we preferred a more narrow fix for 1.4, I could just explicitly mark the encoding in .rs.rpc.package_skeleton() (and leave this for 1.4-Juliet-Rose).

@kevinushey

Copy link
Copy Markdown
Collaborator Author

#8449 is the more narrow version of the fix scoped to the problem @melissa-barca saw.

@jmcphers

Copy link
Copy Markdown
Member

Just merged that one -- can you rebase this to Juliet Rose?

@gtritchie gtritchie added this to the v1.4-juliet-rose milestone Dec 1, 2020
@kevinushey
kevinushey force-pushed the bugfix/r-json-rpc-utf8 branch from e060563 to 8714ff8 Compare December 3, 2020 20:33
@kevinushey
kevinushey changed the base branch from master to v1.4-juliet-rose December 3, 2020 20:33
@kevinushey

Copy link
Copy Markdown
Collaborator Author

Rebased to JR.

@melissa-barca melissa-barca left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@kevinushey
kevinushey merged commit c88c577 into v1.4-juliet-rose Dec 7, 2020
@valerie-rstudio
valerie-rstudio deleted the bugfix/r-json-rpc-utf8 branch January 21, 2022 18:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

encoding of strings passed to R RPC methods should be marked as UTF-8 warnings on session launch when username contains non-ASCII chars

4 participants