Skip to content

Commit

Permalink
Fix for issue fmtlib#3319.
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Shchapov <[email protected]>
  • Loading branch information
phprus committed Feb 25, 2023
1 parent 5b83020 commit 3351f9d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions include/fmt/std.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ inline void write_escaped_path<std::filesystem::path::value_type>(
template <typename Char>
struct formatter<std::filesystem::path, Char>
: formatter<basic_string_view<Char>> {
template <typename ParseContext> FMT_CONSTEXPR auto parse(ParseContext& ctx) {
this->set_debug_format(false);
return formatter<basic_string_view<Char>>::parse(ctx);
}
template <typename FormatContext>
auto format(const std::filesystem::path& p, FormatContext& ctx) const ->
typename FormatContext::iterator {
Expand Down
14 changes: 14 additions & 0 deletions test/std-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,20 @@ TEST(ranges_std_test, format_vector_path) {
#endif
}

TEST(ranges_std_test, format_quote_path) {
// Test quoted problem described in #3319.
#ifdef __cpp_lib_filesystem
auto v =
std::vector<std::filesystem::path>{"path1/file1.txt", "path2/file2.txt"};
EXPECT_EQ(fmt::format("{}", v), "[\"path1/file1.txt\", \"path2/file2.txt\"]");

# ifdef __cpp_lib_optional
auto o = std::optional<std::filesystem::path>("path/file.txt");
EXPECT_EQ(fmt::format("{}", o), "optional(\"path/file.txt\")");
# endif
#endif
}

TEST(std_test, thread_id) {
EXPECT_FALSE(fmt::format("{}", std::this_thread::get_id()).empty());
}
Expand Down

0 comments on commit 3351f9d

Please sign in to comment.