strformat corrupt cyrillic symbols #1128

Closed
uujava opened this Issue Oct 15, 2013 · 1 comment

2 participants

@uujava

puts Time.at(100).strftime('Процесс завершен за %S')
will puts garbage.
From the RubyDateFormatter code it looks like it does not set proper encoding when creating InputStreamReader and appending bytes to output.
Unable to attache the patch - copying it below:

Index: core/src/main/java/org/jruby/util/RubyDateFormatter.java
<+>UTF-8
===================================================================
--- core/src/main/java/org/jruby/util/RubyDateFormatter.java    (date 1381750123000)
+++ core/src/main/java/org/jruby/util/RubyDateFormatter.java    (date 1381841997000)
@@ -258,7 +258,7 @@
         }
 
         ByteArrayInputStream in = new ByteArrayInputStream(pattern.getUnsafeBytes(), pattern.getBegin(), pattern.getRealSize());
-        Reader reader = new InputStreamReader(in);
+        Reader reader = new InputStreamReader(in, pattern.getEncoding().getCharset());
         lexer.yyreset(reader);
 
         Token token;
@@ -549,9 +549,7 @@
             // reset formatter
             formatter = RubyTimeOutputFormatter.DEFAULT_FORMATTER;
 
-            for (int i = 0; i < output.length(); i++) {
-                toAppendTo.append(output.charAt(i));
-            }
+            toAppendTo.append(output.getBytes(toAppendTo.getEncoding().getCharset()));
         }
 
         RubyString str = context.runtime.newString(toAppendTo);
@headius headius closed this in bb5b52c Oct 21, 2013
@jlbfalcao

same problem with portuguese. Can't use 1.7.5 for this reason.

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