gnucash unstable: Multiple changes pushed

John Ralls jralls at code.gnucash.org
Sun Apr 8 20:42:24 EDT 2018


Updated	 via  https://github.com/Gnucash/gnucash/commit/7a0f0d57 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/89a1cfd2 (commit)
	from  https://github.com/Gnucash/gnucash/commit/11ac05ae (commit)



commit 7a0f0d57c809a2177d015ad4a961e2b1d34dfee6
Author: John Ralls <jralls at ceridwen.us>
Date:   Sun Apr 8 17:37:39 2018 -0700

    Bug 782144 - git-master - Save Corrupts Data File / Not Open Data File
    
    After much thrashing this turned out to be caused by a date string
    with a 3-digit year and that caused an unexpected boost::bad_cast
    exception from boost::posix_time::time_from_string().
    
    To prevent that and anything like it, pre-parse the string with
    regular expressions to classify them and split out the timezone
    if there is one. If neither (perhaps eventually none) of the
    regexes match throw std::invalid_argument. The C function will
    catch this and return 0.

diff --git a/libgnucash/engine/gnc-datetime.cpp b/libgnucash/engine/gnc-datetime.cpp
index e86d47e..61fa701 100644
--- a/libgnucash/engine/gnc-datetime.cpp
+++ b/libgnucash/engine/gnc-datetime.cpp
@@ -282,19 +282,31 @@ GncDateTimeImpl::GncDateTimeImpl(std::string str) :
     m_time(unix_epoch, utc_zone)
 {
     if (str.empty()) return;
-
-    auto tzpos = str.find_first_of("+-", str.find(":"));
-    auto tzptr = tz_from_string(tzpos != str.npos ? str.substr(tzpos) : "");
-    if (tzpos != str.npos && str[tzpos - 1] == ' ') --tzpos;
-
+    TZ_Ptr tzptr;
     try
     {
-        bool delimited = str.find("-") == 4;
-        if (!delimited)
-            str.insert(8, "T");
-        auto pdt = delimited ?
-            boost::posix_time::time_from_string(str.substr(0, tzpos)) :
-            boost::posix_time::from_iso_string(str.substr(0,tzpos));
+        static const boost::regex delim_iso("^(\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}(?:\\.\\d{0,9})?)\\s*([+-]\\d{2}(?::?\\d{2})?)?$");
+        static const boost::regex non_delim("^(\\d{14}(?:\\.\\d{0,9})?)\\s*([+-]\\d{2}\\s*(:?\\d{2})?)?$");
+        PTime pdt;
+        boost::smatch sm;
+        if (regex_match(str, sm, non_delim))
+        {
+            std::string time_str(sm[1]);
+            time_str.insert(8, "T");
+            pdt = boost::posix_time::from_iso_string(time_str);
+        }
+        else if (regex_match(str, sm, delim_iso))
+        {
+            pdt = boost::posix_time::time_from_string(sm[1]);
+        }
+        else
+        {
+            throw(std::invalid_argument("The date string was not formatted in a way that GncDateTime(std::string) knows how to parse."));
+        }
+        std::string tzstr("");
+        if (sm[2].matched)
+            tzstr += sm[2];
+        tzptr = tz_from_string(tzstr);
         m_time = LDT(pdt.date(), pdt.time_of_day(), tzptr,
                          LDTBase::NOT_DATE_TIME_ON_ERROR);
     }

commit 89a1cfd24af529c7ca885ec7e90d198908133cbf
Author: John Ralls <jralls at ceridwen.us>
Date:   Sun Apr 8 14:11:28 2018 -0700

    Add note about ALLOW_OLD_GETTEXT.

diff --git a/README.dependencies b/README.dependencies
index 2239492..0b16ca7 100644
--- a/README.dependencies
+++ b/README.dependencies
@@ -66,7 +66,10 @@ Libraries/Deps
   gtk+3			3.14.0
   guile			2.2.0 or 2.0.0
   libxml2		2.5.10
-  gettext		0.19.6
+  gettext               0.19.6                  Can use older if you pass
+                                                -DALLOW_OLD_CMAKE to cmake;
+                                                doesn't include all file types
+                                                when building gnucash.pot.
   libxslt, including xsltproc
   ICU                                           International Compnents for
                                                 Unicode



Summary of changes:
 README.dependencies                |  5 ++++-
 libgnucash/engine/gnc-datetime.cpp | 34 +++++++++++++++++++++++-----------
 2 files changed, 27 insertions(+), 12 deletions(-)



More information about the gnucash-changes mailing list