Skip to content

Commit

Permalink
readdlm(bytearray) shouldn't modify bytearray (#32255)
Browse files Browse the repository at this point in the history
* readdlm(bytearray) shouldn't modify bytearray

* Update stdlib/DelimitedFiles/src/DelimitedFiles.jl

Co-Authored-By: Jeff Bezanson <jeff.bezanson@gmail.com>
  • Loading branch information
2 people authored and StefanKarpinski committed Jun 8, 2019
1 parent ad42d5d commit 7038210
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion stdlib/DelimitedFiles/src/DelimitedFiles.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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...)
Expand Down
6 changes: 6 additions & 0 deletions stdlib/DelimitedFiles/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand Down

0 comments on commit 7038210

Please sign in to comment.