diff --git a/src/common/datetimefmt.cpp b/src/common/datetimefmt.cpp index 9da429c7c8..1dfdd1b45f 100644 --- a/src/common/datetimefmt.cpp +++ b/src/common/datetimefmt.cpp @@ -751,7 +751,7 @@ wxDateTime::ParseRfc822Date(const wxString& originalDate, wxString::const_iterat // to the date string (32 being the length of a typical RFC822 timestamp). const wxString date(originalDate + wxString(32, '\0')); - const wxString::const_iterator pEnd = date.end(); + const wxString::const_iterator pEnd = date.begin() + originalDate.length(); wxString::const_iterator p = date.begin(); // 1. week day (optional) @@ -896,7 +896,8 @@ wxDateTime::ParseRfc822Date(const wxString& originalDate, wxString::const_iterat // the explicit offset given: it has the form of hhmm bool plus = *p++ == '+'; - if ( !wxIsdigit(*p) || !wxIsdigit(*(p + 1)) ) + if ( p == pEnd || !wxIsdigit(*p) || + p + 1 == pEnd || !wxIsdigit(*(p + 1)) ) return false; @@ -905,7 +906,8 @@ wxDateTime::ParseRfc822Date(const wxString& originalDate, wxString::const_iterat p += 2; - if ( !wxIsdigit(*p) || !wxIsdigit(*(p + 1)) ) + if ( p == pEnd || !wxIsdigit(*p) || + p + 1 == pEnd || !wxIsdigit(*(p + 1)) ) return false; // minutes @@ -920,7 +922,7 @@ wxDateTime::ParseRfc822Date(const wxString& originalDate, wxString::const_iterat { // the symbolic timezone given: may be either military timezone or one // of standard abbreviations - if ( !*(p + 1) ) + if ( p + 1 == pEnd ) { // military: Z = UTC, J unused, A = -1, ..., Y = +12 static const int offsets[26] = @@ -939,7 +941,7 @@ wxDateTime::ParseRfc822Date(const wxString& originalDate, wxString::const_iterat else { // abbreviation - const wxString tz(p, date.end()); + const wxString tz(p, pEnd); if ( tz == wxT("UT") || tz == wxT("UTC") || tz == wxT("GMT") ) offset = 0; else if ( tz == wxT("AST") ) diff --git a/tests/datetime/datetimetest.cpp b/tests/datetime/datetimetest.cpp index 9f48a82245..9a48b3a781 100644 --- a/tests/datetime/datetimetest.cpp +++ b/tests/datetime/datetimetest.cpp @@ -1106,6 +1106,18 @@ void DateTimeTestCase::TestParseRFC822() true }, + { + "Sat, 18 Dec 1999 10:48:30 G", // military time zone + { 18, wxDateTime::Dec, 1999, 17, 48, 30 }, + true + }, + + { + "Sat, 18 Dec 1999 10:48:30 Q", // military time zone + { 18, wxDateTime::Dec, 1999, 6, 48, 30 }, + true + }, + // seconds are optional according to the RFC { "Sun, 01 Jun 2008 16:30 +0200", @@ -1159,12 +1171,30 @@ void DateTimeTestCase::TestParseRFC822() false }, + { + "Sun, 01 Jun 2008 16:39:10 +020", // truncated time zone + { 0 }, + false + }, + { "Sun, 01 Jun 2008 16:39:10 +02", // truncated time zone { 0 }, false }, + { + "Sun, 01 Jun 2008 16:39:10 +0", // truncated time zone + { 0 }, + false + }, + + { + "Sun, 01 Jun 2008 16:39:10 +", // truncated time zone + { 0 }, + false + }, + { "Sun, 01 Jun 2008 16:39:10 GM", // truncated time zone { 0 },