diff --git a/fmt/format.h b/fmt/format.h index 267ae6c2..c6ee44d1 100644 --- a/fmt/format.h +++ b/fmt/format.h @@ -4111,10 +4111,14 @@ template void format_arg(fmt::BasicFormatter &f, const Char *&format_str, const ArgJoin& e) { const Char* end = format_str; - if (*end == ':') - ++end; - while (*end && *end != '}') + int brace_level = 1; + while (*end) { + if (*end == '}' && --brace_level == 0) + break; + if (*end == '{') + ++brace_level; ++end; + } if (*end != '}') FMT_THROW(FormatError("missing '}' in format string")); diff --git a/test/format-test.cc b/test/format-test.cc index 3f2ac042..c836541e 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1611,13 +1611,15 @@ TEST(FormatTest, JoinArg) { v2.push_back(1.2f); v2.push_back(3.4f); - EXPECT_EQ("(1, 2, 3)", format("({})", join(v1 + 0, v1 + 3, ", "))); - EXPECT_EQ("(1)", format("({})", join(v1 + 0, v1 + 1, ", "))); - EXPECT_EQ("()", format("({})", join(v1 + 0, v1 + 0, ", "))); - EXPECT_EQ("(001, 002, 003)", format("({:03})", join(v1 + 0, v1 + 3, ", "))); - EXPECT_EQ("(+01.20, +03.40)", format("({:+06.2f})", join(v2.begin(), v2.end(), ", "))); + EXPECT_EQ("(1, 2, 3)", format("({})", join(v1, v1 + 3, ", "))); + EXPECT_EQ("(1)", format("({})", join(v1, v1 + 1, ", "))); + EXPECT_EQ("()", format("({})", join(v1, v1, ", "))); + EXPECT_EQ("(001, 002, 003)", format("({:03})", join(v1, v1 + 3, ", "))); + EXPECT_EQ("(+01.20, +03.40)", + format("({:+06.2f})", join(v2.begin(), v2.end(), ", "))); - EXPECT_EQ(L"(1, 2, 3)", format(L"({})", join(v1 + 0, v1 + 3, L", "))); + EXPECT_EQ(L"(1, 2, 3)", format(L"({})", join(v1, v1 + 3, L", "))); + EXPECT_EQ("1, 2, 3", format("{0:{1}}", join(v1, v1 + 3, ", "), 1)); #if FMT_HAS_GXX_CXX11 EXPECT_EQ("(1, 2, 3)", format("({})", join(v1, ", ")));