Skip to content

Commit

Permalink
Showing 2 changed files with 9 additions and 1 deletion.
7 changes: 7 additions & 0 deletions spec/std/io/io_spec.cr
Original file line number Diff line number Diff line change
@@ -568,6 +568,13 @@ describe IO do
io.set_encoding("UTF-8", invalid: :skip)
io.gets_to_end.should eq "{/* */}"
end

it "decodes incomplete multibyte sequence with skip (#3285)" do
bytes = Bytes[195, 229, 237, 229, 240, 224, 246, 232, 255, 32, 241, 234, 240, 232, 239, 242, 224, 32, 48, 46, 48, 49, 50, 54, 32, 241, 229, 234, 243, 237, 228, 10]
m = MemoryIO.new(bytes)
m.set_encoding("UTF-8", invalid: :skip)
m.gets_to_end.should eq(" 0.0126 \n")
end
end

describe "encode" do
3 changes: 2 additions & 1 deletion src/io/encoding.cr
Original file line number Diff line number Diff line change
@@ -102,7 +102,8 @@ module IO
result = @iconv.convert(pointerof(@in_buffer), pointerof(@in_buffer_left), pointerof(out_buffer), pointerof(out_buffer_left))
@out_slice = @out_buffer[0, OUT_BUFFER_SIZE - out_buffer_left]
if result == -1
if Errno.value == Errno::EILSEQ
case Errno.value
when Errno::EILSEQ, Errno::EINVAL
@iconv.handle_invalid(pointerof(@in_buffer), pointerof(@in_buffer_left))
end

0 comments on commit 3aadab7

Please sign in to comment.