From: "ioquatix (Samuel Williams) via ruby-core" Date: 2024-01-14T02:59:31+00:00 Subject: [ruby-core:116195] [Ruby master Bug#18805] IO::Buffer is inconsistent when returning a string from an empty buffer Issue #18805 has been updated by ioquatix (Samuel Williams). As a 2nd issue was created about the similar issue, I think it's worth improving. See https://github.com/ruby/ruby/pull/9532 for the proposed changes. ---------------------------------------- Bug #18805: IO::Buffer is inconsistent when returning a string from an empty buffer https://bugs.ruby-lang.org/issues/18805#change-106211 * Author: procmarco (Marco Concetto Rudilosso) * Status: Open * Priority: Normal * Assignee: ioquatix (Samuel Williams) * Backport: 2.7: UNKNOWN, 3.0: UNKNOWN, 3.1: UNKNOWN ---------------------------------------- I���ve been using `IO::Buffer` and I found it to be slightly inconsistent when it comes to returning empty string for empty buffers. for example, a slice of an allocated buffer with `size = 0`, returns `""` with `get_string`, as an example: ```ruby buffer = IO::Buffer.new(5) empty_buffer = buffer.slice(0,0) puts empty_buffer.size # this prints 0 empty_buffer.get_string # this returns "" ``` but, if you create a buffer with IO::Buffer.new(0) then it stops working ```ruby empty_buffer = IO::Buffer.new(0) puts empty_buffer.size # this prints 0 empty_buffer.get_string # this raises The buffer is not allocated! (IO::Buffer::AllocationError) ``` Is this working as intended? It would be good I think to have a consistent experience where the base case (buffer with size 0) always returns an empty string. I have a prototype of a possible patch I could send upstream to fix it, which would check the size of the buffer and if 0 it would always return an empty string. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/