fix issue 21592 - two stack traces if high surrogate is printed

This commit is contained in:
aG0aep6G 2021-02-17 08:24:14 +01:00 committed by The Dlang Bot
parent c9e9729769
commit 3debd58cb4

View file

@ -1577,8 +1577,11 @@ Throws: `Exception` if the file is not opened.
void write(S...)(S args)
{
import std.traits : isBoolean, isIntegral, isAggregateType;
import std.utf : UTFException;
auto w = lockingTextWriter();
foreach (arg; args)
{
try
{
alias A = typeof(arg);
static if (isAggregateType!A || is(A == enum))
@ -1613,6 +1616,14 @@ Throws: `Exception` if the file is not opened.
formattedWrite(w, "%s", arg);
}
}
catch (UTFException e)
{
/* Reset the writer so that it doesn't throw another
UTFException on destruction. */
w.highSurrogate = '\0';
throw e;
}
}
}
/**
@ -3766,6 +3777,18 @@ void main()
assert(e && e.msg == "Attempting to write to closed File");
}
@safe unittest // https://issues.dlang.org/show_bug.cgi?id=21592
{
import std.exception : collectException;
import std.utf : UTFException;
static import std.file;
auto deleteme = testFilename();
scope(exit) std.file.remove(deleteme);
auto f = File(deleteme, "w");
auto e = collectException!UTFException(f.writeln(wchar(0xD801)));
assert(e.next is null);
}
version (StdStressTest)
{
// https://issues.dlang.org/show_bug.cgi?id=15768