From 7fd7ef32c22e25d41b579795cce11d30e303d54d Mon Sep 17 00:00:00 2001 From: Orivej Desh Date: Thu, 10 Oct 2019 21:51:43 +0000 Subject: [PATCH] Support color printing strings with zero bytes This is a clean up after #1351. --- include/fmt/color.h | 3 +-- test/color-test.cc | 2 ++ 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/include/fmt/color.h b/include/fmt/color.h index dbaafb2ac2ea..5e859207f343 100644 --- a/include/fmt/color.h +++ b/include/fmt/color.h @@ -503,8 +503,7 @@ void vprint(std::FILE* f, const text_style& ts, const S& format, basic_format_args > args) { basic_memory_buffer buf; internal::vformat_to(buf, ts, to_string_view(format), args); - buf.push_back(Char(0)); - internal::fputs(buf.data(), f); + std::fwrite(buf.data(), 1, buf.size(), f); } /** diff --git a/test/color-test.cc b/test/color-test.cc index fde3a0c58a14..bd05592c7447 100644 --- a/test/color-test.cc +++ b/test/color-test.cc @@ -45,6 +45,8 @@ TEST(ColorsTest, ColorsPrint) { EXPECT_WRITE(stdout, fmt::print(bg(fmt::terminal_color::bright_magenta), "tbmagenta"), "\x1b[105mtbmagenta\x1b[0m"); + EXPECT_WRITE(stdout, fmt::print(fmt::emphasis::bold, "{}", std::string("a\0b", 3)), + std::string("\x1b[1ma\0b\x1b[0m", 11)); } TEST(ColorsTest, Format) {