From 83d11b5a00f8a79c9f4b8caef219ca707034f023 Mon Sep 17 00:00:00 2001 From: Alex Fabijanic Date: Thu, 22 May 2014 03:08:41 -0500 Subject: [PATCH] fixed GH #363: DateTimeParser tryParse/parse --- CHANGELOG | 1 + Foundation/src/DateTimeParser.cpp | 3 ++ .../testsuite/src/DateTimeParserTest.cpp | 31 +++++++++++++++++++ .../testsuite/src/DirectoryIteratorsTest.cpp | 8 ++--- Foundation/testsuite/src/StringTest.cpp | 2 +- doc/99100-ReleaseNotes.page | 3 +- 6 files changed, 42 insertions(+), 6 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 247f8fdca..cb8a55f82 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -69,6 +69,7 @@ Release 1.5.3 (2014-05-xx) - fixed GH #154 Add support for MYSQL_TYPE_NEWDECIMAL to Poco::Data::MySQL - fixed GH #290: Unicode support - fixed GH #318: Logger local time doesn't automatically account for DST +- fixed GH #363: DateTimeParser tryParse/parse Release 1.5.2 (2013-09-16) ========================== diff --git a/Foundation/src/DateTimeParser.cpp b/Foundation/src/DateTimeParser.cpp index d2df7488f..5b99e0f43 100644 --- a/Foundation/src/DateTimeParser.cpp +++ b/Foundation/src/DateTimeParser.cpp @@ -46,6 +46,9 @@ namespace Poco { void DateTimeParser::parse(const std::string& fmt, const std::string& str, DateTime& dateTime, int& timeZoneDifferential) { + if (fmt.empty() || str.empty()) + throw SyntaxException("Empty string."); + int year = 0; int month = 0; int day = 0; diff --git a/Foundation/testsuite/src/DateTimeParserTest.cpp b/Foundation/testsuite/src/DateTimeParserTest.cpp index 1b3c41c2e..57322c3e3 100644 --- a/Foundation/testsuite/src/DateTimeParserTest.cpp +++ b/Foundation/testsuite/src/DateTimeParserTest.cpp @@ -505,6 +505,37 @@ void DateTimeParserTest::testCustom() assert (dt.hour() == 12); assert (dt.minute() == 30); assert (dt.second() == 0); + + assert (!DateTimeParser::tryParse("%h:%M %a", "", dt, tzd)); + assert (!DateTimeParser::tryParse("", "12:30 PM", dt, tzd)); + assert (!DateTimeParser::tryParse("", "", dt, tzd)); + + try + { + DateTimeParser::parse("%h:%M %a", "", tzd); + fail ("must fail"); + } + catch (SyntaxException&) + { + } + + try + { + DateTimeParser::parse("", "12:30 PM", tzd); + fail ("must fail"); + } + catch (SyntaxException&) + { + } + + try + { + DateTimeParser::parse("", "", tzd); + fail ("must fail"); + } + catch (SyntaxException&) + { + } } diff --git a/Foundation/testsuite/src/DirectoryIteratorsTest.cpp b/Foundation/testsuite/src/DirectoryIteratorsTest.cpp index da1392a8e..d2d94ff79 100644 --- a/Foundation/testsuite/src/DirectoryIteratorsTest.cpp +++ b/Foundation/testsuite/src/DirectoryIteratorsTest.cpp @@ -49,7 +49,7 @@ void DirectoryIteratorsTest::testDirectoryIterator() result.push_back(file); } - assertEquals(7, result.size()); + assertEquals(7, (long) result.size()); } @@ -68,7 +68,7 @@ void DirectoryIteratorsTest::testSortedDirectoryIterator() result.push_back(file); } - assertEquals(7, result.size()); + assertEquals(7, (long) result.size()); assertEquals("first", result[0]); assertEquals("1", result[1]); assertEquals("2", result[2]); @@ -94,7 +94,7 @@ void DirectoryIteratorsTest::testSimpleRecursiveDirectoryIterator() result.push_back(file); } - assertEquals(20, result.size()); + assertEquals(20, (long) result.size()); } @@ -113,7 +113,7 @@ void DirectoryIteratorsTest::testSiblingsFirstRecursiveDirectoryIterator() result.push_back(file); } - assertEquals(20, result.size()); + assertEquals(20, (long) result.size()); } diff --git a/Foundation/testsuite/src/StringTest.cpp b/Foundation/testsuite/src/StringTest.cpp index 7116cc4bf..9d4d86a46 100644 --- a/Foundation/testsuite/src/StringTest.cpp +++ b/Foundation/testsuite/src/StringTest.cpp @@ -969,7 +969,7 @@ void StringTest::testIntToString() { char pResult[POCO_MAX_INT_STRING_LEN]; std::size_t sz = POCO_MAX_INT_STRING_LEN; - intToStr(0, 10, pResult, sz, false, sz + 1, ' '); + intToStr(0, 10, pResult, sz, false, (int) sz + 1, ' '); fail ("must throw RangeException"); } catch (RangeException&) { } } diff --git a/doc/99100-ReleaseNotes.page b/doc/99100-ReleaseNotes.page index fa38567d5..1967ca13c 100644 --- a/doc/99100-ReleaseNotes.page +++ b/doc/99100-ReleaseNotes.page @@ -71,7 +71,8 @@ AAAIntroduction - fixed GH #154 Add support for MYSQL_TYPE_NEWDECIMAL to Poco::Data::MySQL - fixed GH #290: Unicode support - fixed GH #318: Logger local time doesn't automatically account for DST - + - fixed GH #363: DateTimeParser tryParse/parse + !!Incompatible Changes and Possible Transition Issues - Data::ODBC: UTF-16 Unicode is now directly mapped and recognized as type by ODBC.