Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Critical
-
Resolution: Unresolved
-
Affects Version/s: JRuby 1.6RC1
-
Fix Version/s: JRuby 1.6
-
Component/s: Core Classes/Modules, Ruby 1.9.2
-
Labels:None
-
Number of attachments :
Description
This is a tricky one. IO#ungetc needs to accept a String and unget the first character. Currently, we only support ungetting a byte, so this requires changing ChannelStream too.
This missing feature leads to at least two rubyspec failures:
4) IO#readpartial reads after ungetc with data in the buffer ERROR TypeError: can't convert String into Integer org/jruby/RubyIO.java:2389:in `ungetc19' /Users/headius/projects/jruby/spec/ruby/core/io/readpartial_spec.rb:35:in `(root)' org/jruby/RubyBasicObject.java:1697:in `instance_eval19' org/jruby/RubyEnumerable.java:1260:in `all_p' org/jruby/RubyArray.java:1676:in `each' /Users/headius/projects/jruby/spec/ruby/core/io/readpartial_spec.rb:4:in `(root)' org/jruby/RubyKernel.java:1075:in `load19' /Users/headius/projects/jruby/spec/ruby/core/io/readpartial_spec.rb:56:in `files' org/jruby/RubyBasicObject.java:1697:in `instance_eval19' org/jruby/RubyArray.java:1676:in `each' 5) IO#readpartial reads after ungetc without data in the buffer ERROR TypeError: can't convert String into Integer org/jruby/RubyIO.java:2389:in `ungetc19' /Users/headius/projects/jruby/spec/ruby/core/io/readpartial_spec.rb:43:in `(root)' org/jruby/RubyBasicObject.java:1697:in `instance_eval19' org/jruby/RubyEnumerable.java:1260:in `all_p' org/jruby/RubyArray.java:1676:in `each' /Users/headius/projects/jruby/spec/ruby/core/io/readpartial_spec.rb:4:in `(root)' org/jruby/RubyKernel.java:1075:in `load19' /Users/headius/projects/jruby/spec/ruby/core/io/readpartial_spec.rb:56:in `files' org/jruby/RubyBasicObject.java:1697:in `instance_eval19' org/jruby/RubyArray.java:1676:in `each'
Issue Links
- relates to
-
JRUBY-5465
[1.9] ChannelStream doesn't handle multibyte characters from ungetc properly
-
This patch solves the problem but I'm not sure if it breaks any other cases:
diff --git a/src/org/jruby/RubyIO.java b/src/org/jruby/RubyIO.java index 808f670..bc42c17 100644 --- a/src/org/jruby/RubyIO.java +++ b/src/org/jruby/RubyIO.java @@ -2398,6 +2398,11 @@ public class RubyIO extends RubyObject { return getRuntime().getNil(); } + if (number instanceof RubyString) { + RubyString str = (RubyString) number; + number = getRuntime().newFixnum(str.getByteList().get(0)); + } + return ungetcCommon(number, myOpenFile); }If you agree I can push it with a regresion test.