Skip to content

Commit

Permalink
Fix sprint
Browse files Browse the repository at this point in the history
  • Loading branch information
ScottPJones committed Oct 25, 2023
1 parent 8120e2c commit e17d2f5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
13 changes: 6 additions & 7 deletions src/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -213,16 +213,15 @@ print(io::IO, str::MaybeSub{<:Str{<:CSE}}) = (_write(UTF8CSE, io, str) ; nothing
print(io::IO, str::MaybeSub{T}) where {T<:Str{<:Union{Binary_CSEs,ASCIICSE,UTF8_CSEs}}} =
(_fastwrite(io, str); nothing)

function Base.sprint(f::Function, ::Type{T}, args...;
context=nothing, sizehint::Integer=0) where {T<:Union{String, Str}}
function Base.sprint(f::Function, ::T, args...; context=nothing, sizehint::Integer=0
) where {C<:Union{Binary_CSEs,ASCIICSE,UTF8_CSEs},T<:Str{C}}
s = IOBuffer(sizehint=sizehint)
if context !== nothing
f(IOContext(s, context), args...)
S = get(context, :type, T)
S(resize!(s.data, s.size))
if context != nothing
f(context isa Tuple ? IOContext(s, context...) : IOContext(s, context), args...)
Str(get(s.dict, :type, C), resize!(s.data, s.size))
else
f(s, args...)
T(resize!(s.data, s.size))
String(_unsafe_take!(s))
end
end

Expand Down
2 changes: 1 addition & 1 deletion test/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,7 @@ end
@test Meta.lower(Main, sym) === sym
res = string(Meta.parse(string(Char(0xdcdb)," = 1"),1,raise=false)[1])
@static if VERSION v"1.5.0-DEV.460"
@test res == "\$(Expr(:error, \"invalid UTF-8 sequence\"))"
@test contains(res, "invalid UTF-8 sequence")
else
@test startswith(res, "\$(Expr(:error, \"invalid character \\\"\\udcdb\\\"")
@test endswith(res, "\"))")
Expand Down

0 comments on commit e17d2f5

Please sign in to comment.