File tree Expand file tree Collapse file tree 3 files changed +9
-2
lines changed
spec/ruby/library/stringio/shared Expand file tree Collapse file tree 3 files changed +9
-2
lines changed Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ New features:
6
6
7
7
Bug fixes:
8
8
9
+ * Fix ` StringIO ` to set position correctly after reading multi-byte characters (#2207 , @aardvark179 ).
9
10
10
11
Compatibility:
11
12
Original file line number Diff line number Diff line change @@ -211,7 +211,7 @@ def each_byte
211
211
d = @__data__
212
212
string = d . string
213
213
214
- while d . pos < string . length
214
+ while d . pos < string . bytesize
215
215
check_readable
216
216
byte = string . getbyte d . pos
217
217
d . pos += 1
@@ -468,7 +468,7 @@ def read(length = nil, buffer = nil)
468
468
buffer . replace str if buffer
469
469
end
470
470
471
- d . pos += str . length
471
+ d . pos += str . bytesize
472
472
str
473
473
end
474
474
Original file line number Diff line number Diff line change 89
89
@io . send ( @method )
90
90
@io . pos . should eql ( 7 )
91
91
end
92
+
93
+ it "correctly update the current position in bytes when multi-byte characters are used" do
94
+ @io . print ( "example\u03A3 " ) # Overwrite the original string with 8 characters containing 9 bytes.
95
+ @io . send ( @method )
96
+ @io . pos . should eql ( 9 )
97
+ end
92
98
end
93
99
94
100
describe :stringio_read_nil , shared : true do
You can’t perform that action at this time.
0 commit comments