Project

General

Profile

Actions

Bug #18768

closed

Inconsistent behavior of IO, StringIO and String each_line methods when return paragraph and chomp: true passed

Added by andrykonchin (Andrew Konchin) over 2 years ago. Updated over 2 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:108500]

Description

In IO, StringIO and String methods that return lines (e.g. each, each_line, gets, readline, readlines) behave in a different way when the following parameters are passed

  • separator is "" and
  • chomp is true.

They truncate the new line characters between paragraphs and the trailing one differently:

"a\n\nb\n\nc\n".each_line("", chomp: true).to_a
#=> ["a\n", "b\n", "c\n"]

StringIO.new("a\n\nb\n\nc\n").each_line("", chomp: true).to_a
#=> ["a\n", "b\n", "c"]

File.open('chomp.txt').each_line("", chomp: true).to_a
#=> ["a", "b", "c\n"]

The text file content is the same:

File.read('chomp.txt')
#=> "a\n\nb\n\nc\n"

Expected behavior - they return the same result.


Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #18770: Inconsistent behavior of IO/StringIO's each methods when called with nil as a separator, limit and chomp: trueClosedActions
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0