mirror of
https://github.com/ruby/ruby.git
synced 2025-08-15 13:39:04 +02:00
merge revision(s) 35e124832e
: [Backport #20755]
[Bug #20755] Frozen string should not be writable via IO::Buffer
This commit is contained in:
parent
12ea98e8c8
commit
5ce0ba0d41
3 changed files with 28 additions and 2 deletions
|
@ -843,7 +843,8 @@ rb_io_buffer_get_bytes(VALUE self, void **base, size_t *size)
|
||||||
static inline void
|
static inline void
|
||||||
io_buffer_get_bytes_for_writing(struct rb_io_buffer *buffer, void **base, size_t *size)
|
io_buffer_get_bytes_for_writing(struct rb_io_buffer *buffer, void **base, size_t *size)
|
||||||
{
|
{
|
||||||
if (buffer->flags & RB_IO_BUFFER_READONLY) {
|
if (buffer->flags & RB_IO_BUFFER_READONLY ||
|
||||||
|
(!NIL_P(buffer->source) && OBJ_FROZEN(buffer->source))) {
|
||||||
rb_raise(rb_eIOBufferAccessError, "Buffer is not writable!");
|
rb_raise(rb_eIOBufferAccessError, "Buffer is not writable!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -248,6 +248,31 @@ class TestIOBuffer < Test::Unit::TestCase
|
||||||
assert_equal "Hello World", hello
|
assert_equal "Hello World", hello
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_transfer
|
||||||
|
hello = %w"Hello World".join(" ")
|
||||||
|
buffer = IO::Buffer.for(hello)
|
||||||
|
transferred = buffer.transfer
|
||||||
|
assert_equal "Hello World", transferred.get_string
|
||||||
|
assert_predicate buffer, :null?
|
||||||
|
assert_raise IO::Buffer::AccessError do
|
||||||
|
transferred.set_string("Goodbye")
|
||||||
|
end
|
||||||
|
assert_equal "Hello World", hello
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_transfer_in_block
|
||||||
|
hello = %w"Hello World".join(" ")
|
||||||
|
buffer = IO::Buffer.for(hello, &:transfer)
|
||||||
|
assert_equal "Hello World", buffer.get_string
|
||||||
|
buffer.set_string("Ciao!")
|
||||||
|
assert_equal "Ciao! World", hello
|
||||||
|
hello.freeze
|
||||||
|
assert_raise IO::Buffer::AccessError do
|
||||||
|
buffer.set_string("Hola")
|
||||||
|
end
|
||||||
|
assert_equal "Ciao! World", hello
|
||||||
|
end
|
||||||
|
|
||||||
def test_locked
|
def test_locked
|
||||||
buffer = IO::Buffer.new(128, IO::Buffer::INTERNAL|IO::Buffer::LOCKED)
|
buffer = IO::Buffer.new(128, IO::Buffer::INTERNAL|IO::Buffer::LOCKED)
|
||||||
|
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
|
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
|
||||||
#define RUBY_VERSION_TEENY 5
|
#define RUBY_VERSION_TEENY 5
|
||||||
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
|
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
|
||||||
#define RUBY_PATCHLEVEL 105
|
#define RUBY_PATCHLEVEL 106
|
||||||
|
|
||||||
#include "ruby/version.h"
|
#include "ruby/version.h"
|
||||||
#include "ruby/internal/abi.h"
|
#include "ruby/internal/abi.h"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue