mirror of
https://github.com/dlang/phobos.git
synced 2025-04-27 21:51:40 +03:00
fix issue 23488 - std.format.sformat mishandles char ranges
This commit is contained in:
parent
6034c4f1ed
commit
26c7f44de8
1 changed files with 21 additions and 0 deletions
|
@ -1563,6 +1563,14 @@ char[] sformat(Char, Args...)(return scope char[] buf, scope const(Char)[] fmt,
|
|||
{
|
||||
char[] buf;
|
||||
size_t i;
|
||||
void put(char c)
|
||||
{
|
||||
if (buf.length <= i)
|
||||
throw new RangeError(__FILE__, __LINE__);
|
||||
|
||||
buf[i] = c;
|
||||
i += 1;
|
||||
}
|
||||
void put(dchar c)
|
||||
{
|
||||
char[4] enc;
|
||||
|
@ -1687,6 +1695,19 @@ if (isSomeString!(typeof(fmt)))
|
|||
assert(u == v);
|
||||
}
|
||||
|
||||
@safe unittest // https://issues.dlang.org/show_bug.cgi?id=23488
|
||||
{
|
||||
static struct R
|
||||
{
|
||||
string s = "Ü";
|
||||
bool empty() { return s.length == 0; }
|
||||
char front() { return s[0]; }
|
||||
void popFront() { s = s[1 .. $]; }
|
||||
}
|
||||
char[2] buf;
|
||||
assert(sformat(buf, "%s", R()) == "Ü");
|
||||
}
|
||||
|
||||
version (StdUnittest)
|
||||
private void formatReflectTest(T)(ref T val, string fmt, string formatted, string fn = __FILE__, size_t ln = __LINE__)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue