Skip to content

Commit

Permalink
Merge pull request #2958 from sinkuu/fix_14059_format
Browse files Browse the repository at this point in the history
Issue 14059 - Formatted write with wrong formatting string
  • Loading branch information
JakobOvrum committed Feb 6, 2015
2 parents 1d4a341 + 4a0f817 commit 3299c63
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion std/format.d
Expand Up @@ -867,15 +867,19 @@ struct FormatSpec(Char)
// Get the matching balanced paren
for (uint innerParens;;)
{
enforce(j < trailing.length,
enforceFmt(j + 1 < trailing.length,
text("Incorrect format specifier: %", trailing[i .. $]));
if (trailing[j++] != '%')
{
// skip, we're waiting for %( and %)
continue;
}
if (trailing[j] == '-') // for %-(
{
++j; // skip
enforceFmt(j < trailing.length,
text("Incorrect format specifier: %", trailing[i .. $]));
}
if (trailing[j] == ')')
{
if (innerParens-- == 0) break;
Expand Down Expand Up @@ -1199,6 +1203,19 @@ struct FormatSpec(Char)
assert(f.spec == 's');
}

// Issue 14059
unittest
{
import std.array : appender;
auto a = appender!(string)();

auto f = FormatSpec!char("%-(%s%");
assertThrown(f.writeUpToNextSpec(a));

f = FormatSpec!char("%(%-");
assertThrown(f.writeUpToNextSpec(a));
}

/**
Helper function that returns a $(D FormatSpec) for a single specifier given
in $(D fmt)
Expand Down

0 comments on commit 3299c63

Please sign in to comment.