From c41c713dedd3bfb592767edbaafa8c4887515be3 Mon Sep 17 00:00:00 2001 From: Nathan Zimmerberg <39104088+nhz2@users.noreply.github.com> Date: Fri, 26 Apr 2024 10:29:32 -0400 Subject: [PATCH] Fix typo in `readuntil` (#54259) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Also use `isascii` instead of `≤ '\x7f'` because `isascii` handles malformed `Char` slightly better. --- base/iostream.jl | 4 ++-- test/read.jl | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/base/iostream.jl b/base/iostream.jl index 0ee51b9b98efd..f39d9013a7fc9 100644 --- a/base/iostream.jl +++ b/base/iostream.jl @@ -449,8 +449,8 @@ function readuntil_string(s::IOStream, delim::UInt8, keep::Bool) @_lock_ios s ccall(:jl_readuntil, Ref{String}, (Ptr{Cvoid}, UInt8, UInt8, UInt8), s.ios, delim, 1, !keep) end readuntil(s::IOStream, delim::AbstractChar; keep::Bool=false) = - delim ≤ '\x7f' ? readuntil_string(s, delim % UInt8, keep) : - String(unsafe_take!(copyuntil(IOBuffer(sizehint=70), s, delim; keep))) + isascii(delim) ? readuntil_string(s, delim % UInt8, keep) : + String(_unsafe_take!(copyuntil(IOBuffer(sizehint=70), s, delim; keep))) function readline(s::IOStream; keep::Bool=false) @_lock_ios s ccall(:jl_readuntil, Ref{String}, (Ptr{Cvoid}, UInt8, UInt8, UInt8), s.ios, '\n', 1, keep ? 0 : 2) diff --git a/test/read.jl b/test/read.jl index 283381668c28a..34224c146864e 100644 --- a/test/read.jl +++ b/test/read.jl @@ -170,6 +170,10 @@ for (name, f) in l local t, s, m, kept @test readuntil(io(t), s) == m @test readuntil(io(t), s, keep=true) == kept + if isone(length(s)) + @test readuntil(io(t), first(s)) == m + @test readuntil(io(t), first(s), keep=true) == kept + end @test readuntil(io(t), SubString(s, firstindex(s))) == m @test readuntil(io(t), SubString(s, firstindex(s)), keep=true) == kept @test readuntil(io(t), GenericString(s)) == m