From 1cd3af87d2599d5828aff81c7294433911cb0003 Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Thu, 6 Jun 2019 09:42:37 -0400 Subject: [PATCH 1/2] readdlm(bytearray) shouldn't modify bytearray --- 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 99bd0a7217cae..1882ac6f9a7f2 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(copy(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 c1a9700d09d99..900d97ace2122 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()) From 86ac4fe3ef7524140304a660d564a1e8391c50da Mon Sep 17 00:00:00 2001 From: "Steven G. Johnson" Date: Thu, 6 Jun 2019 16:52:05 -0400 Subject: [PATCH 2/2] Update stdlib/DelimitedFiles/src/DelimitedFiles.jl Co-Authored-By: Jeff Bezanson --- stdlib/DelimitedFiles/src/DelimitedFiles.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stdlib/DelimitedFiles/src/DelimitedFiles.jl b/stdlib/DelimitedFiles/src/DelimitedFiles.jl index 1882ac6f9a7f2..2a545eb413bae 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(copy(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...)