Bug #701

Wrong behaviour of StringIO#ungetc

Added by Yauheni Akhotnikau over 3 years ago. Updated 10 months ago.

[ruby-core:19632]
Status:Closed Start date:10/30/2008
Priority:Normal Due date:
Assignee:- % Done:

100%

Category:lib
Target version:1.9.1 Release Candidate
ruby -v:

Description

This is the behaviour of StringIO#ungetc from Ruby 1.8.7:

irb(main):001:0> require 'stringio'
=> true
irb(main):002:0> a=StringIO.new('abcd')
=> #<StringIO:0x2ba7e24>
irb(main):003:0> a.getc;a.getc;a.getc;a.tell # Read 'a','b','c'. Current position is on 'd'.
=> 3
irb(main):004:0> a.ungetc(?#)
=> nil
irb(main):005:0> a.tell
=> 2
irb(main):006:0> a.string
=> "ab#d"
irb(main):007:0>

And this is from Ruby 1.9.1 (Win32 version):

irb(main):001:0> require 'stringio'
=> true
irb(main):002:0> a=StringIO.new('abcd')
=> #<StringIO:0xe0388c>
irb(main):003:0> a.getc; a.getc; a.getc; a.tell
=> 3
irb(main):004:0> a.ungetc('#')
=> nil
irb(main):005:0> a.tell
=> 1
irb(main):006:0> a.string
=> "a#cd"

a.ungetc should replace 'c' to '#', but not 'b'.

Associated revisions

Revision 20150
Added by Yukihiro Matsumoto over 3 years ago

* ext/stringio/stringio.c (strio_ungetc): ungetc position should not be changed from 1.8. [ruby-core:19632]

History

Updated by Yukihiro Matsumoto over 3 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100
Applied in changeset r20150.

Also available in: Atom PDF