(PUP-8226) Set JRuby KCode, source encoding, and external encoding#61
(PUP-8226) Set JRuby KCode, source encoding, and external encoding#61haus merged 2 commits intopuppetlabs:masterfrom
Conversation
| (let [encoding-string (str (.getEncoding kcode))] | ||
| ;; RubyInstanceConfig exposes the encoding setters directly, while the | ||
| ;; ScriptingContainer does not. | ||
| (if (instance? RubyInstanceConfig jruby) |
There was a problem hiding this comment.
Do you think it is worth being explicit here and using cond instead of if so that we can test for both RubyInstanceConfig and ScriptingContainer?
|
We talked in person about this, but I think it's worth breaking the function up into one that expects a |
|
Updated. |
|
Note, this proved really hard to test at the unit level, because the encoding bug only appears when parsing Ruby source files to execute, which is difficult to do in the context of the configured scripting container. Edit: Haus found a way to test this. |
|
Nope. I totally didn't. My test passes, but doesn't fail without this change, so that's too bad. |
This commit adds a function that can configure the KCode, external encoding, and source encoding of the JRuby scripting containers. We use this function when initializing our JRuby instances to set these encodings to UTF-8, to avoid parsing source files as US-ASCII, which can cause issues with translation interpolation. Note that this is only relevant in JRuby 1.7; in JRuby 9K, source files are parsed as UTF-8 by default.
| (org.jruby.runtime.profile.builtin ProfileOutput) | ||
| (java.io File))) | ||
| (java.io File) | ||
| (org.jruby.util KCode))) |
There was a problem hiding this comment.
nit: if we're changing this can we put the imports in alphabetical order?
| (.setKCode kcode) | ||
| (.setSourceEncoding encoding-string) | ||
| (.setExternalEncoding encoding-string))) | ||
| jruby) |
There was a problem hiding this comment.
doto returns its first argument so this is unnecessary
| (if (instance? RubyInstanceConfig jruby) | ||
| (set-config-encoding kcode jruby) | ||
| (set-config-encoding kcode (.getRubyInstanceConfig (.getProvider jruby)))) | ||
| jruby) |
This commit adds a function that can configure the KCode, external
encoding, and source encoding of the JRuby scripting containers. We use
this function when initializing our JRuby instances to set these
encodings to UTF-8, to avoid parsing source files as US-ASCII, which can
cause issues with translation interpolation.
Note that this is only relevant in JRuby 1.7; in JRuby 9K, source files are parsed
as UTF-8 by default.