Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 407245534ed4
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: b9e090712eac
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Oct 3, 2015

  1. fix bug in spec where incorrect args were passed to test #gets with l…

    …imit
    
    Tricky one to find. The original spec used #gets(1) to read one
    char. Unfortunately, this arg format ends up setting a separator
    to $/ so the logic ends up calling
    EachReader#read_to_separator_with_limit instead of
    EachReader#read_to_limit. By passing nil, as in #gets(nil, 1),
    then we force the code paths to call read_to_limit.
    chuckremes committed Oct 3, 2015
    Copy the full SHA
    1cf5d4a View commit details
  2. fix handling of multi-byte chars when reading with char limits

    This fixes several specs shared by gets, foreach, and readline.
    The EachReader class needs a good refactoring at this point
    but for now I just want to commit working code.
    chuckremes committed Oct 3, 2015
    Copy the full SHA
    b9e0907 View commit details
Showing with 11 additions and 7 deletions.
  1. +9 −5 kernel/common/io.rb
  2. +2 −2 spec/ruby/core/io/gets_spec.rb
14 changes: 9 additions & 5 deletions kernel/common/io.rb
Original file line number Diff line number Diff line change
@@ -1985,10 +1985,12 @@ def read_to_separator_with_limit
# the pattern/separator which may be >1. therefore, add the separator size.
count += separator_size
bytes = count < wanted ? count : wanted
substring = buffer.slice!(0, bytes)
str << substring
str << buffer.slice!(0, bytes)

str = IO.read_encode(@io, str)
# Always read to char boundary because the +limit+ may have cut a multi-byte
# character in the middle. Returning such a string would have an invalid encoding.
buffer += (@io.read(PEEK_AHEAD_LIMIT) || '') if buffer.size < PEEK_AHEAD_LIMIT
str, bytes_read = read_to_char_boundary(@io, str, buffer)
str.taint

$. = @io.increment_lineno
@@ -2004,7 +2006,7 @@ def read_to_separator_with_limit
str << buffer.slice!(0, wanted)

# replenish the buffer if we don't have enough bytes to satisfy the peek ahead
buffer += @io.read(PEEK_AHEAD_LIMIT) if buffer.size < PEEK_AHEAD_LIMIT
buffer += (@io.read(PEEK_AHEAD_LIMIT) || '') if buffer.size < PEEK_AHEAD_LIMIT
str, bytes_read = read_to_char_boundary(@io, str, buffer)
str.taint

@@ -2056,8 +2058,10 @@ def read_to_limit
begin
str << @io.read(wanted)

str = try_to_force_encoding(@io, str)
buffer = (@io.read(PEEK_AHEAD_LIMIT) || '')
str, bytes_read = read_to_char_boundary(@io, str, buffer)
str.taint
@io.ungetc(buffer)

$. = @io.increment_lineno
yield str
4 changes: 2 additions & 2 deletions spec/ruby/core/io/gets_spec.rb
Original file line number Diff line number Diff line change
@@ -228,11 +228,11 @@
end

it "reads limit bytes and extra bytes when limit is reached not at character boundary" do
[@io.gets(1), @io.gets(1)].should == ["朝", "日"]
[@io.gets(nil, 1), @io.gets(nil, 1)].should == ["朝", "日"]
end

it "read limit bytes and extra bytes with maximum of 16" do
@io.gets(7).should == "朝日\xE3" + "\x81\xE3" * 8
@io.gets(nil, 7).should == "朝日\xE3" + "\x81\xE3" * 8
end

after :each do