Details
-
Type:
Bug
-
Status:
Reopened
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: JRuby 1.5.1
-
Fix Version/s: JRuby 1.5.1, JRuby 1.7.4
-
Component/s: None
-
Labels:None
-
Testcase included:yes
-
Number of attachments :
Description
The following tests fail on JRuby 1.5.1 if file.encoding is set to any value which cannot encode Japanese characters (we discovered it with windows-1252.)
The Unicode characters present in the original script become "?????". As the script itself is already a string and the code embedding it never converts to a byte[], I believe that there should be no reason for it to convert anything to the default encoding.
public class TestUnicodeCharacters { String orig = "\u6625\u304C\u6765\u305F\u3002"; String scriptlet = "str = \"" + orig + "\" ; puts str ; str"; Writer writer = new StringWriter(); @Test public void testCharacterEncodingViaScriptEngine() throws Exception { ScriptEngine engine = new ScriptEngineManager().getEngineByExtension("rb"); ScriptContext context = engine.getContext(); context.setWriter(writer); String result = (String) engine.eval(scriptlet, context); checkValues(result); } @Test public void testCharacterEncodingViaScriptContainer() throws Exception { ScriptingContainer container = new ScriptingContainer(); container.setWriter(writer); // The next lines don't help anyway, but I half expected them to... //container.setCompatVersion(CompatVersion.RUBY1_9); //container.setKCode(KCode.UTF8); String result = (String) container.runScriptlet(scriptlet); checkValues(result); } private void checkValues(String returnedResult) { assertEquals("Wrong result returned", orig, returnedResult); assertEquals("Wrong result printed", orig, writer.toString().trim()); } }
Activity
Hiro Asari
made changes -
| Field | Original Value | New Value |
|---|---|---|
| Description |
The following tests fail on JRuby 1.5.1 if file.encoding is set to any value which cannot encode Japanese characters (we discovered it with windows-1252.)
The Unicode characters present in the original script become "?????". As the script itself is already a string and the code embedding it never converts to a byte[], I believe that there should be no reason for it to convert anything to the default encoding. {code:java} public class TestUnicodeCharacters { String orig = "\u3070\u304B\u3084\u308D\u3046"; String scriptlet = "str = \"" + orig + "\" ; puts str ; str"; Writer writer = new StringWriter(); @Test public void testCharacterEncodingViaScriptEngine() throws Exception { ScriptEngine engine = new ScriptEngineManager().getEngineByExtension("rb"); ScriptContext context = engine.getContext(); context.setWriter(writer); String result = (String) engine.eval(scriptlet, context); checkValues(result); } @Test public void testCharacterEncodingViaScriptContainer() throws Exception { ScriptingContainer container = new ScriptingContainer(); container.setWriter(writer); // The next lines don't help anyway, but I half expected them to... //container.setCompatVersion(CompatVersion.RUBY1_9); //container.setKCode(KCode.UTF8); String result = (String) container.runScriptlet(scriptlet); checkValues(result); } private void checkValues(String returnedResult) { assertEquals("Wrong result returned", orig, returnedResult); assertEquals("Wrong result printed", orig, writer.toString().trim()); } } {code} |
The following tests fail on JRuby 1.5.1 if file.encoding is set to any value which cannot encode Japanese characters (we discovered it with windows-1252.)
The Unicode characters present in the original script become "?????". As the script itself is already a string and the code embedding it never converts to a byte[], I believe that there should be no reason for it to convert anything to the default encoding. {code:java} public class TestUnicodeCharacters { String orig = "\u6625\u304C\u6765\u305F\u3002"; String scriptlet = "str = \"" + orig + "\" ; puts str ; str"; Writer writer = new StringWriter(); @Test public void testCharacterEncodingViaScriptEngine() throws Exception { ScriptEngine engine = new ScriptEngineManager().getEngineByExtension("rb"); ScriptContext context = engine.getContext(); context.setWriter(writer); String result = (String) engine.eval(scriptlet, context); checkValues(result); } @Test public void testCharacterEncodingViaScriptContainer() throws Exception { ScriptingContainer container = new ScriptingContainer(); container.setWriter(writer); // The next lines don't help anyway, but I half expected them to... //container.setCompatVersion(CompatVersion.RUBY1_9); //container.setKCode(KCode.UTF8); String result = (String) container.runScriptlet(scriptlet); checkValues(result); } private void checkValues(String returnedResult) { assertEquals("Wrong result returned", orig, returnedResult); assertEquals("Wrong result printed", orig, writer.toString().trim()); } } {code} |
Yoko Harada
made changes -
| Status | Open [ 1 ] | Resolved [ 5 ] |
| Fix Version/s | JRuby 1.5.1 [ 16519 ] | |
| Resolution | Not A Bug [ 6 ] |
Charles Oliver Nutter
made changes -
| Status | Resolved [ 5 ] | Closed [ 6 ] |
Trejkaz
made changes -
| Resolution | Not A Bug [ 6 ] | |
| Status | Closed [ 6 ] | Reopened [ 4 ] |
Thomas E Enebo
made changes -
| Fix Version/s | JRuby 1.7.1 [ 18842 ] |
Thomas E Enebo
made changes -
| Fix Version/s | JRuby 1.7.2 [ 19008 ] | |
| Fix Version/s | JRuby 1.7.1 [ 18842 ] |
Thomas E Enebo
made changes -
| Fix Version/s | JRuby 1.7.3 [ 19009 ] | |
| Fix Version/s | JRuby 1.7.2 [ 19008 ] |
Thomas E Enebo
made changes -
| Fix Version/s | JRuby 1.7.4 [ 19106 ] | |
| Fix Version/s | JRuby 1.7.3 [ 19009 ] |
Ugh, I swear I put it under Embedding, but it says None now. :-/