Skip to content

strformat corrupt cyrillic symbols #1128

@uujava

Description

@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);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions