Skip to content

Commit 05960a5

Browse files
stevengjJeffBezanson
authored andcommitted
readdlm(bytearray) shouldn't modify bytearray (#32255)
* readdlm(bytearray) shouldn't modify bytearray * Update stdlib/DelimitedFiles/src/DelimitedFiles.jl Co-Authored-By: Jeff Bezanson <[email protected]> (cherry picked from commit 7038210)
1 parent 83e7363 commit 05960a5

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

stdlib/DelimitedFiles/src/DelimitedFiles.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ readdlm(input, dlm::AbstractChar, T::Type, eol::AbstractChar; opts...) =
226226
readdlm_auto(input, dlm, T, eol, false; opts...)
227227

228228
readdlm_auto(input::Vector{UInt8}, dlm::AbstractChar, T::Type, eol::AbstractChar, auto::Bool; opts...) =
229-
readdlm_string(String(input), dlm, T, eol, auto, val_opts(opts))
229+
readdlm_string(String(copyto!(Base.StringVector(length(input)), input)), dlm, T, eol, auto, val_opts(opts))
230230
readdlm_auto(input::IO, dlm::AbstractChar, T::Type, eol::AbstractChar, auto::Bool; opts...) =
231231
readdlm_string(read(input, String), dlm, T, eol, auto, val_opts(opts))
232232
function readdlm_auto(input::AbstractString, dlm::AbstractChar, T::Type, eol::AbstractChar, auto::Bool; opts...)

stdlib/DelimitedFiles/test/runtests.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,12 @@ let data = "\"1\",\"灣\"\"灣灣灣灣\",\"3\""
288288
@test readdlm(IOBuffer(data), ',') == Any[1 "\"灣灣灣灣" 3]
289289
end
290290

291+
# reading from a byte array (#16731)
292+
let data = Vector{UInt8}("1,2,3\n4,5,6"), origdata = copy(data)
293+
@test readdlm(data, ',') == [1 2 3; 4 5 6]
294+
@test data == origdata
295+
end
296+
291297
# issue #11484: useful error message for invalid readdlm filepath arguments
292298
@test_throws ArgumentError readdlm(tempdir())
293299

0 commit comments

Comments
 (0)