Project

General

Profile

Actions

Backport #2431

closed

StringIO#{gets,readlines} with "" (paragraph mode) trims last "\n"

Added by nahi (Hiroshi Nakamura) over 14 years ago. Updated almost 13 years ago.


Description

=begin
Fixed in r17739 at trunk.

0% ruby -v -rstringio -e 'p StringIO.new("a\n\n").readlines("")'
ruby 1.8.8dev (2009-12-03 revision 25983) [i686-linux]
["a\n"]
0% ruby19 -v -rstringio -e 'p StringIO.new("a\n\n").readlines("")'
ruby 1.9.2dev (2009-12-01 trunk 25970) [i686-linux]
["a\n\n"]
0%
=end

Actions #1

Updated by nobu (Nobuyoshi Nakada) over 14 years ago

  • Assignee set to mame (Yusuke Endoh)

=begin

=end

Actions #2

Updated by vvs (Vladimir Sizikov) over 14 years ago

=begin
So, is the current 1.8.6-1.8.7 behavior considered a bug or feature?

Once I fixed the behavior in JRuby to match the latest MRI behavior, I'm getting 6 RubySpec failures, where all those tests expect that in paragraph mode only one \n is returned, not two.

I can change the specs, but I need to know the official position here.
=end

Actions #3

Updated by nahi (Hiroshi Nakamura) over 14 years ago

=begin
2009/12/7 Vladimir Sizikov :

Once I fixed the behavior in JRuby to match the latest MRI behavior, I'm getting 6 RubySpec failures, where all those tests expect that in paragraph mode only one \n is returned, not two.

Would you please point the 6 tests? It must be helpful to discuss this issue.

// NaHi

=end

Actions #4

Updated by vvs (Vladimir Sizikov) over 14 years ago

=begin
Hi,

On Sun, Dec 6, 2009 at 11:37 PM, NAKAMURA, Hiroshi wrote:

Would you please point the 6 tests? It must be helpful to discuss this issue.

Sure thing. Here you go (today's latest RubySpecs used):

#> mspec -t j library/stringio
jruby 1.5.0.dev (ruby 1.8.7 patchlevel 174) (2009-12-06 6fd3279) (Java
HotSpot(TM) Client VM 1.6.0_17) [x86-java]
............FF.......F.....F...........FF...............

StringIO#each_line when passed a separator yields each paragraph when
passed an empty String as separator FAILED
Expected ["para1\n\n", "para2\n\n", "para3"]
to equal ["para1\n", "para2\n", "para3"]

D:/work/jruby-dev/rubyspec.git/library/stringio/shared/each.rb:43
D:/work/jruby-dev/rubyspec.git/library/stringio/each_line_spec.rb:5
D:/work/jruby-dev/rubyspec.git/library/stringio/each_line_spec.rb:55:in `load'
D:/work/jruby-dev/mspec.git/bin/mspec-run:8

StringIO#each when passed a separator yields each paragraph when
passed an empty String as separator FAILED
Expected ["para1\n\n", "para2\n\n", "para3"]
to equal ["para1\n", "para2\n", "para3"]

D:/work/jruby-dev/rubyspec.git/library/stringio/shared/each.rb:43
D:/work/jruby-dev/rubyspec.git/library/stringio/each_spec.rb:5
D:/work/jruby-dev/rubyspec.git/library/stringio/each_spec.rb:55:in `load'
D:/work/jruby-dev/mspec.git/bin/mspec-run:8

StringIO#gets when passed [separator] returns the next paragraph when
the passed separator is an empty String FAILED
Expected "this is\n\n"
to equal "this is\n"

D:/work/jruby-dev/rubyspec.git/library/stringio/gets_spec.rb:42
D:/work/jruby-dev/rubyspec.git/library/stringio/gets_spec.rb:4
D:/work/jruby-dev/rubyspec.git/library/stringio/gets_spec.rb:55:in `load'
D:/work/jruby-dev/mspec.git/bin/mspec-run:8

StringIO#lines when passed a separator yields each paragraph when
passed an empty String as separator FAILED
Expected ["para1\n\n", "para2\n\n", "para3"]
to equal ["para1\n", "para2\n", "para3"]

D:/work/jruby-dev/rubyspec.git/library/stringio/shared/each.rb:43
D:/work/jruby-dev/rubyspec.git/library/stringio/lines_spec.rb:6
D:/work/jruby-dev/rubyspec.git/library/stringio/lines_spec.rb:5
D:/work/jruby-dev/rubyspec.git/library/stringio/lines_spec.rb:55:in `load'
D:/work/jruby-dev/mspec.git/bin/mspec-run:8

StringIO#readline when passed [separator] returns the next paragraph
when the passed separator is an empty String FAILED
Expected "this is\n\n"
to equal "this is\n"

D:/work/jruby-dev/rubyspec.git/library/stringio/readline_spec.rb:43
D:/work/jruby-dev/rubyspec.git/library/stringio/readline_spec.rb:5
D:/work/jruby-dev/rubyspec.git/library/stringio/readline_spec.rb:55:in `load'
D:/work/jruby-dev/mspec.git/bin/mspec-run:8

StringIO#readlines when passed [separator] returns an Array containing
all paragraphs when the passed separator is an empty String FAILED
Expected ["this is\n\n", "an example"]
to equal ["this is\n", "an example"]

D:/work/jruby-dev/rubyspec.git/library/stringio/readlines_spec.rb:31
D:/work/jruby-dev/rubyspec.git/library/stringio/readlines_spec.rb:4
D:/work/jruby-dev/rubyspec.git/library/stringio/readlines_spec.rb:55:in `load'
D:/work/jruby-dev/mspec.git/bin/mspec-run:8

Finished in 0.810000 seconds

56 files, 381 examples, 699 expectations, 6 failures, 0 errors

Thanks,
--Vladimir

=end

Actions #5

Updated by nahi (Hiroshi Nakamura) over 14 years ago

=begin
Hi Vladimir,

2009/12/7 Vladimir Sizikov :

#> mspec -t j library/stringio

All the failed tests are for StringIO, right? Then we are free to fix
StringIO behavior as well as 1.9 which is consistent with generic IO.

FYI: No tests for JRuby failed by my fix at
http://github.com/nahi/jruby/commit/a5ffa1bba2e644ef056eb9efc37900c9d86b8a47

// NaHi

=end

Actions #6

Updated by vvs (Vladimir Sizikov) over 14 years ago

=begin
On Mon, Dec 7, 2009 at 10:54 AM, NAKAMURA, Hiroshi wrote:

All the failed tests are for StringIO, right?

Yes.

Then we are free to fix
StringIO behavior as well as 1.9 which is consistent with generic IO.

Yeah, fixing the specs is not a problem. But we need the clear
statement from ruby-core, is the current MRI 1.8.* behavior for
StringIO considered a bug and needs to be fixed, or is it considered a
feature (albeit a bit inconsistent with the standard IO behavior).

Thanks,
--Vladimir

=end

Actions #7

Updated by nahi (Hiroshi Nakamura) over 14 years ago

=begin
Hi Vladimir,

Yeah, fixing the specs is not a problem. But we need the clear
statement from ruby-core, is the current MRI 1.8.* behavior for
StringIO considered a bug and needs to be fixed, or is it considered a
feature (albeit a bit inconsistent with the standard IO behavior).

Author(nobu) assigned this ticket to mame so it's a bug to be fixed in
ruby_1_8 (1.8.8dev). Branch mgmt policy allow to fix a bug by
committer.

Aside from this, 1.8.7 may not incorporate this fix even if it's a
bug. I strongly recommend to apply this fix to 1.8.7 as well (to
resolve StringIO-IO interface mismatch as you said) but it's
shyouhei's job.

// NaHi

=end

Actions #8

Updated by nobu (Nobuyoshi Nakada) over 14 years ago

  • Assignee changed from mame (Yusuke Endoh) to nahi (Hiroshi Nakamura)

=begin

=end

Actions #9

Updated by nahi (Hiroshi Nakamura) over 14 years ago

  • Status changed from Open to Closed

=begin
Applied r17739 at r26140 for 1.8.8dev with Author's confirmation.
=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0