Check chrono spec starts with %
This commit is contained in:
parent
115001a3b1
commit
8c56919bd2
@ -626,6 +626,8 @@ template <typename Char, typename Handler>
|
|||||||
FMT_CONSTEXPR const Char* parse_chrono_format(const Char* begin,
|
FMT_CONSTEXPR const Char* parse_chrono_format(const Char* begin,
|
||||||
const Char* end,
|
const Char* end,
|
||||||
Handler&& handler) {
|
Handler&& handler) {
|
||||||
|
if (begin == end || *begin == '}') return begin;
|
||||||
|
if (*begin != '%') FMT_THROW(format_error("invalid format"));
|
||||||
auto ptr = begin;
|
auto ptr = begin;
|
||||||
while (ptr != end) {
|
while (ptr != end) {
|
||||||
auto c = *ptr;
|
auto c = *ptr;
|
||||||
|
@ -507,6 +507,10 @@ TEST(chrono_test, invalid_specs) {
|
|||||||
"invalid format");
|
"invalid format");
|
||||||
EXPECT_THROW_MSG((void)fmt::format(runtime("{:%Oq}"), sec), fmt::format_error,
|
EXPECT_THROW_MSG((void)fmt::format(runtime("{:%Oq}"), sec), fmt::format_error,
|
||||||
"invalid format");
|
"invalid format");
|
||||||
|
EXPECT_THROW_MSG((void)fmt::format(runtime("{:abc}"), sec), fmt::format_error,
|
||||||
|
"invalid format");
|
||||||
|
EXPECT_THROW_MSG((void)fmt::format(runtime("{:.2f}"), sec), fmt::format_error,
|
||||||
|
"invalid format");
|
||||||
}
|
}
|
||||||
|
|
||||||
auto format_tm(const std::tm& time, fmt::string_view spec,
|
auto format_tm(const std::tm& time, fmt::string_view spec,
|
||||||
|
Loading…
Reference in New Issue
Block a user