-
-
Notifications
You must be signed in to change notification settings - Fork 925
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
string encoding is incorrect when compiling to .class files via jrubyc #4445
Comments
Possibly related to this code which opens the file to compile with https://github.com/jruby/jruby/blob/9.1.5.0/lib/ruby/stdlib/jruby/compiler.rb#L128 |
Are you using javac to produce normal-looking Java classes (using --java or --javac) or are you just using it to obfuscate code? If it's the former, your analysis is probably correct; the code is being parsed using an incorrect encoding. This feature was always experimental, but it shouldn't be a hard fix. Simplest answer might be to just allow the default encoding, omitting "ASCII-8BIT" altogether. That should be simple enough for you to put in a PR. If it's the latter, we have more investigation to do. |
In our case we're using it so we don't ship our native ruby sources, so more in the vein of obfuscation. |
Ok, then somewhere in the pipeline we're reading those sources in with an incorrect encoding. The line you linked to is probably the right place. I'll modify the code to just use system default encoding (or encoding pragma) and add a flag to allow specifying encoding. |
@headius - thanks! Yes, that looks like that is what is happening. The script file is loaded as a binary string encoded as |
I have a workaround for you: specify the file encoding with an I'm working on a fix. The two paths (plain jrubyc versus jrubyc --java) appear to parse the content differently...for no obvious reason. |
I have pushed a fix but we need a test for this. |
Environment
Expected Behavior
I expect the default encoding of a string in ruby 2.x compatible jruby to be
UTF-8
and notASCII-8BIT
when no encoding is specified in the source file header.Actual Behavior
Notice how the default encoding of the empty string that is declared when run from the .class file generated by jrubyc is
ASCII-8BIT
, but when run via jruby it isUTF-8
.The docs here indicate:
jruby 9.1.6.0 seems to also suffer from the same problem:
jruby 9.1.7.0 looks to have a separate problem that prevents even this simple example from running:
The text was updated successfully, but these errors were encountered: