Skip to content

Commit e17d2f5

Browse files
committed
Fix sprint
1 parent 8120e2c commit e17d2f5

File tree

2 files changed

+7
-8
lines changed

2 files changed

+7
-8
lines changed

src/io.jl

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,16 +213,15 @@ print(io::IO, str::MaybeSub{<:Str{<:CSE}}) = (_write(UTF8CSE, io, str) ; nothing
213213
print(io::IO, str::MaybeSub{T}) where {T<:Str{<:Union{Binary_CSEs,ASCIICSE,UTF8_CSEs}}} =
214214
(_fastwrite(io, str); nothing)
215215

216-
function Base.sprint(f::Function, ::Type{T}, args...;
217-
context=nothing, sizehint::Integer=0) where {T<:Union{String, Str}}
216+
function Base.sprint(f::Function, ::T, args...; context=nothing, sizehint::Integer=0
217+
) where {C<:Union{Binary_CSEs,ASCIICSE,UTF8_CSEs},T<:Str{C}}
218218
s = IOBuffer(sizehint=sizehint)
219-
if context !== nothing
220-
f(IOContext(s, context), args...)
221-
S = get(context, :type, T)
222-
S(resize!(s.data, s.size))
219+
if context != nothing
220+
f(context isa Tuple ? IOContext(s, context...) : IOContext(s, context), args...)
221+
Str(get(s.dict, :type, C), resize!(s.data, s.size))
223222
else
224223
f(s, args...)
225-
T(resize!(s.data, s.size))
224+
String(_unsafe_take!(s))
226225
end
227226
end
228227

test/basic.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -962,7 +962,7 @@ end
962962
@test Meta.lower(Main, sym) === sym
963963
res = string(Meta.parse(string(Char(0xdcdb)," = 1"),1,raise=false)[1])
964964
@static if VERSION v"1.5.0-DEV.460"
965-
@test res == "\$(Expr(:error, \"invalid UTF-8 sequence\"))"
965+
@test contains(res, "invalid UTF-8 sequence")
966966
else
967967
@test startswith(res, "\$(Expr(:error, \"invalid character \\\"\\udcdb\\\"")
968968
@test endswith(res, "\"))")

0 commit comments

Comments
 (0)