Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Injection.invert[String, Array[Byte]](Array[Byte](1, 2, 3, -1, -2, -127)) produces a string that cannot be inverted back #199

Closed
ashwinraghav opened this issue Feb 23, 2015 · 5 comments · Fixed by #237

Comments

@ashwinraghav
Copy link

screen shot 2015-02-23 at 3 17 27 pm

@johnynek
Copy link
Collaborator

I think we need to validate that the byte string is valid UTF-8. It seems Java does not by default. That is really surprising. Why String does not throw an exception is really beyond me here.

@ashwinraghav
Copy link
Author

One way to fix this is discussed here
TLDR;

(new String(Array[Byte](1,2,3,-1,-2,-127).map(_.toChar))).toCharArray.map(_.toByte)

Don't depend on an encoding. Before the transformation, convert to characters arrays.
The string constructor applies no encoding to char arrays.

@ianoc
Copy link
Collaborator

ianoc commented Feb 24, 2015

Thats not going to be correct for characters which take more than one byte though is it?

@mosesn
Copy link
Contributor

mosesn commented Feb 24, 2015

Java lets you report failures in other ways.

@johnynek
Copy link
Collaborator

@mosesn that looks like the way to go.

@johnynek johnynek mentioned this issue Jan 22, 2016
johnynek pushed a commit that referenced this issue Jan 22, 2016
ianoc added a commit that referenced this issue Jan 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants