From 2f8997d3ed1aa846233592d65e0778b54f3cb727 Mon Sep 17 00:00:00 2001 From: Howard Hinnant Date: Tue, 18 Apr 2017 12:02:21 -0400 Subject: [PATCH] Make parse fail if fmt string is not completely consumed. --- date.h | 5 ++--- test/date_test/parse.pass.cpp | 13 +++++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/date.h b/date.h index d3f700c..2131246 100644 --- a/date.h +++ b/date.h @@ -5367,9 +5367,8 @@ read(std::basic_istream& is, CharT a0, Args&& ...args) if (a0 != CharT{}) { auto ic = is.peek(); - if (Traits::eq_int_type(ic, Traits::eof())) - return; - if (!Traits::eq(Traits::to_char_type(ic), a0)) + if (Traits::eq_int_type(ic, Traits::eof()) || + !Traits::eq(Traits::to_char_type(ic), a0)) { is.setstate(std::ios::failbit); return; diff --git a/test/date_test/parse.pass.cpp b/test/date_test/parse.pass.cpp index 89ff4b3..05b666d 100644 --- a/test/date_test/parse.pass.cpp +++ b/test/date_test/parse.pass.cpp @@ -716,6 +716,18 @@ test_Z() } } +void +test_trailing_Z() +{ + std::string format = "%FT%TZ"; + std::string datetime = "2017-2-15T13:13:13"; + std::istringstream input(datetime); + date::sys_seconds tp; + input >> date::parse(format, tp); + assert(input.fail()); + assert(input.eof()); +} + int main() { @@ -743,4 +755,5 @@ main() test_X(); test_z(); test_Z(); + test_trailing_Z(); }