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

Encoding issue on Windows #13

Closed
rpiaggio opened this issue Mar 29, 2016 · 10 comments
Closed

Encoding issue on Windows #13

rpiaggio opened this issue Mar 29, 2016 · 10 comments

Comments

@rpiaggio
Copy link

https://gist.github.com/rpiaggio/1e08ae305a14253da97b

In the Gist above, with expected output (produced by http://www.sassmeister.com/) line 19 shows correct UTF-8 character.

When running sbt-sassify on Linux, this works correctly.

However, when running it on Windows, that line is output as .fa-linkedin:before{content:"?"} with an actual question mark (HEX 3F) in the file.

I'm not sure this is a sbt-sassify issue or an internal libsass issue.

Thank you! (and thank you for sbt-sassify)

@rpiaggio
Copy link
Author

It seems to be a sbt-sassify issue.

Working with grunt-sass on Windows works fine.

@rpiaggio
Copy link
Author

After a bit more investigation, this seems to be originated by the way JNA converts strings: https://jna.java.net/javadoc/overview-summary.html#strings.

From there: When converting Java unicode characters into an array of char, the default platform encoding is used, unless the system property jna.encoding is set to a valid encoding. This property may be set to "UTF8", for example, to ensure all native strings use that encoding.

This would explain why it works in Linux and not on Windows. However, I called sbt with -Djna.encoding=UTF8 and the problem persists.

There is a related question on StackOverflow: http://stackoverflow.com/questions/35871861/jna-result-character-encoding-result-in-utf8, which was ultimately solved by calling another API method that returned wide chars, not available in the case of libsass. However, the user reports jna.encoding not having an effect on output strings.

@irundaia
Copy link
Owner

I was looking into this issue already. I can confirm that it seems to be an encoding issue. I think this issue is occurring when writing the output CSS to a file. (When debugging, I can see that the compiled string is consistent with the output from my OS X results.)

@rpiaggio
Copy link
Author

Hi @irundaia!

Are you using OS X then? I don't know that OS X default encoding is, does the issue happen there? I can confirm that it doesn't happen on Linux.

I was following the JNA path... If JNA is the issue, then I think this could be solved by receiving the CSS output as a Pointer instead of a String in https://github.com/irundaia/sbt-sassify/blob/master/src/org/irundaia/sass/jna/SassLibrary.java#L1357, and then calling pointer.getString(0, "UTF-8") (https://github.com/java-native-access/jna/blob/master/src/com/sun/jna/Pointer.java#L693).

What do you think?

@rpiaggio
Copy link
Author

@irundaia
Copy link
Owner

Yup I've tested it on both OS X and Linux.

Now, the issue does not lie with the interface between JNA and the scala/java code but in the way I wrote the output to the destination file. I converted the String to an Array[Byte] using the String.toBytes() function. Apparently, this messes up the character encoding.

If I instead use String.toBytes(StandardCharsets.UTF_8), it seems to be working properly. I want to run some extra tests on both OS X and Linux to make sure that this does not break their output encoding.

In any case! thanks a bunch for the report!

@rpiaggio
Copy link
Author

Ah, great! Thank you very much for fixing it. Sorry if I overwhelmed you with "off the track" info.

@irundaia
Copy link
Owner

Yup, it's the latter issue. I've tested it on both Linux and OS X, it seems to work there as well. I'm a bit worried though, that this is OS (perhaps even FS) dependant. In any case, I'll release the fix as it is. I hope this solves your issues. If not, please let me know.

@rpiaggio
Copy link
Author

Thank you! I confirmed that the issue is fixed for me.

@irundaia
Copy link
Owner

Great, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants