diff --git a/std/format/spec.d b/std/format/spec.d index e5564c99d..74243becf 100644 --- a/std/format/spec.d +++ b/std/format/spec.d @@ -296,6 +296,8 @@ if (is(Unqual!Char == Char)) } width = 0; + indexStart = 0; + indexEnd = 0; precision = UNSPECIFIED; nested = null; // Parse the spec (we assume we're past '%' already) @@ -834,6 +836,21 @@ if (is(Unqual!Char == Char)) == "$ expected after '*10' in format string"); } +// https://github.com/dlang/phobos/issues/10713 +@safe pure unittest +{ + import std.array : appender; + auto f = FormatSpec!char("%3$d%d"); + + auto w = appender!(char[])(); + f.writeUpToNextSpec(w); + assert(f.indexStart == 3); + + f.writeUpToNextSpec(w); + assert(w.data.length == 0); + assert(f.indexStart == 0); +} + /** Helper function that returns a `FormatSpec` for a single format specifier.