Fix 21131. Detect certain string appending situations and properly

handle them.
This commit is contained in:
Steven Schveighoffer 2020-08-06 20:38:26 -04:00 committed by The Dlang Bot
parent 50751f4392
commit 6065ce793c
2 changed files with 22 additions and 1 deletions

View file

@ -3501,6 +3501,17 @@ if (isDynamicArray!A)
//We do this at the end, in case of exceptions
_data.arr = bigData;
}
else static if (isSomeChar!T && isSomeChar!(ElementType!Range) &&
!is(immutable T == immutable ElementType!Range))
{
// need to decode and encode
import std.utf : decodeFront;
while (!items.empty)
{
auto c = items.decodeFront;
put(c);
}
}
else
{
//pragma(msg, Range.stringof);
@ -3717,6 +3728,16 @@ if (isDynamicArray!A)
assert(result.value != 23);
}
@safe unittest
{
import std.conv : to;
import std.utf : byCodeUnit;
auto str = "ウェブサイト";
auto wstr = appender!wstring();
put(wstr, str.byCodeUnit);
assert(wstr.data == str.to!wstring);
}
//Calculates an efficient growth scheme based on the old capacity
//of data, and the minimum requested capacity.
//arg curLen: The current length