Skip to content

Commit 4285904

Browse files
rikkimaxadamdruppe
authored andcommitted
Fix #10713 - std.format string positions affect all further format specifiers (#10714)
1 parent 64cfcaa commit 4285904

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

phobos/std/format/spec.d

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,8 @@ if (is(Unqual!Char == Char))
296296
}
297297

298298
width = 0;
299+
indexStart = 0;
300+
indexEnd = 0;
299301
precision = UNSPECIFIED;
300302
nested = null;
301303
// Parse the spec (we assume we're past '%' already)
@@ -834,6 +836,21 @@ if (is(Unqual!Char == Char))
834836
== "$ expected after '*10' in format string");
835837
}
836838

839+
// https://github.com/dlang/phobos/issues/10713
840+
@safe pure unittest
841+
{
842+
import std.array : appender;
843+
auto f = FormatSpec!char("%3$d%d");
844+
845+
auto w = appender!(char[])();
846+
f.writeUpToNextSpec(w);
847+
assert(f.indexStart == 3);
848+
849+
f.writeUpToNextSpec(w);
850+
assert(w.data.length == 0);
851+
assert(f.indexStart == 0);
852+
}
853+
837854
/**
838855
Helper function that returns a `FormatSpec` for a single format specifier.
839856

0 commit comments

Comments
 (0)