From 96a1f4f3412e759f4d8ffa89f9e15eed26ae9740 Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Sat, 8 Jun 2019 13:20:22 -0400 Subject: [PATCH] readdlm(bytearray) shouldn't modify bytearray (#32255) * readdlm(bytearray) shouldn't modify bytearray * Update stdlib/DelimitedFiles/src/DelimitedFiles.jl Co-Authored-By: Jeff Bezanson (cherry picked from commit 70382102220ac6fe6f7366b5124a40e016e41119) --- stdlib/DelimitedFiles/src/DelimitedFiles.jl | 2 +- stdlib/DelimitedFiles/test/runtests.jl | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/stdlib/DelimitedFiles/src/DelimitedFiles.jl b/stdlib/DelimitedFiles/src/DelimitedFiles.jl index f68dda36341e3..f4661e33c56ef 100644 --- a/stdlib/DelimitedFiles/src/DelimitedFiles.jl +++ b/stdlib/DelimitedFiles/src/DelimitedFiles.jl @@ -226,7 +226,7 @@ readdlm(input, dlm::AbstractChar, T::Type, eol::AbstractChar; opts...) = readdlm_auto(input, dlm, T, eol, false; opts...) readdlm_auto(input::Vector{UInt8}, dlm::AbstractChar, T::Type, eol::AbstractChar, auto::Bool; opts...) = - readdlm_string(String(input), dlm, T, eol, auto, val_opts(opts)) + readdlm_string(String(copyto!(Base.StringVector(length(input)), input)), dlm, T, eol, auto, val_opts(opts)) readdlm_auto(input::IO, dlm::AbstractChar, T::Type, eol::AbstractChar, auto::Bool; opts...) = readdlm_string(read(input, String), dlm, T, eol, auto, val_opts(opts)) function readdlm_auto(input::AbstractString, dlm::AbstractChar, T::Type, eol::AbstractChar, auto::Bool; opts...) diff --git a/stdlib/DelimitedFiles/test/runtests.jl b/stdlib/DelimitedFiles/test/runtests.jl index f834fea6bc5cb..e537bf306e158 100644 --- a/stdlib/DelimitedFiles/test/runtests.jl +++ b/stdlib/DelimitedFiles/test/runtests.jl @@ -288,6 +288,12 @@ let data = "\"1\",\"灣\"\"灣灣灣灣\",\"3\"" @test readdlm(IOBuffer(data), ',') == Any[1 "灣\"灣灣灣灣" 3] end +# reading from a byte array (#16731) +let data = Vector{UInt8}("1,2,3\n4,5,6"), origdata = copy(data) + @test readdlm(data, ',') == [1 2 3; 4 5 6] + @test data == origdata +end + # issue #11484: useful error message for invalid readdlm filepath arguments @test_throws ArgumentError readdlm(tempdir())