File tree 2 files changed +19
-0
lines changed
2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -180,6 +180,7 @@ check_modifiable(struct StringIO *ptr)
180
180
else if (OBJ_FROZEN_RAW (ptr -> string )) {
181
181
rb_raise (rb_eIOError , "not modifiable string" );
182
182
}
183
+ rb_str_modify (ptr -> string );
183
184
}
184
185
185
186
static VALUE
Original file line number Diff line number Diff line change @@ -14,6 +14,24 @@ def open_file(content)
14
14
15
15
include TestEOF ::Seek
16
16
17
+ def test_do_not_mutate_shared_buffers
18
+ # Ensure we have two strings that are not embedded but have the same shared
19
+ # string reference.
20
+ #
21
+ # In this case, we must use eval because we need two strings literals that
22
+ # are long enough they cannot be embedded, but also contain the same bytes.
23
+
24
+ a = eval ( ( "x" * 1024 ) . dump )
25
+ b = eval ( ( "x" * 1024 ) . dump )
26
+
27
+ s = StringIO . new ( b )
28
+ s . getc
29
+ s . ungetc '#'
30
+
31
+ # We mutated b, so a should not be mutated
32
+ assert_equal ( "x" , a [ 0 ] )
33
+ end
34
+
17
35
def test_version
18
36
assert_kind_of ( String , StringIO ::VERSION )
19
37
end
You can’t perform that action at this time.
0 commit comments