From 088e643d370d55c45bb796e75883efde60ce6734 Mon Sep 17 00:00:00 2001 From: Lauri Nurmi Date: Fri, 18 Mar 2022 15:01:17 +0200 Subject: [PATCH] Do not consume whitespace/delimiters after date in DateParse() Set the end iterator to the end of the actually parsed date, instead of consuming any ultimately unparsed whitespace/delimiters possibly following the date. --- src/common/datetimefmt.cpp | 16 +++++++++------- tests/datetime/datetimetest.cpp | 2 +- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/common/datetimefmt.cpp b/src/common/datetimefmt.cpp index 80682b5788..9da429c7c8 100644 --- a/src/common/datetimefmt.cpp +++ b/src/common/datetimefmt.cpp @@ -1866,17 +1866,19 @@ wxDateTime::ParseDate(const wxString& date, wxString::const_iterator *end) // tokenize the string while ( p != pEnd ) { - // skip white space and date delimiters - if ( wxStrchr(".,/-\t\r\n ", *p) ) - { - ++p; - continue; - } - // modify copy of the iterator as we're not sure if the next token is // still part of the date at all wxString::const_iterator pCopy = p; + // skip white space and date delimiters + while ( pCopy != pEnd && wxStrchr(".,/-\t\r\n ", *pCopy) ) + { + ++pCopy; + } + + if ( pCopy == pEnd ) + break; + // we can have either alphabetic or numeric token, start by testing if // it's the latter unsigned long val; diff --git a/tests/datetime/datetimetest.cpp b/tests/datetime/datetimetest.cpp index 7bf249d548..6104d975fe 100644 --- a/tests/datetime/datetimetest.cpp +++ b/tests/datetime/datetimetest.cpp @@ -1253,7 +1253,7 @@ void DateTimeTestCase::TestDateParse() // valid, but followed by something { "Dec 31 1979 was the end of 70s", - { 31, wxDateTime::Dec, 1979 }, true, "was the end of 70s" }, + { 31, wxDateTime::Dec, 1979 }, true, " was the end of 70s" }, // some invalid ones too { "29 Feb 2006" },