gnucash maint: Multiple changes pushed

Christopher Lam clam at code.gnucash.org
Mon Sep 23 05:55:46 EDT 2019


Updated	 via  https://github.com/Gnucash/gnucash/commit/9832fa39 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/a259ba4a (commit)
	from  https://github.com/Gnucash/gnucash/commit/1a6314e1 (commit)



commit 9832fa397a5ba1ae898ce206baac7a09a5d3a9e2
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sun Sep 22 18:46:12 2019 +0800

    [window-report] show backtrace when report crashes
    
    * exposes a SCM string last-captured-error containing last backtrace
    * when rendering report-crash window, include it

diff --git a/gnucash/report/report-gnome/window-report.c b/gnucash/report/report-gnome/window-report.c
index d884df647..077650584 100644
--- a/gnucash/report/report-gnome/window-report.c
+++ b/gnucash/report/report-gnome/window-report.c
@@ -274,10 +274,16 @@ gnc_html_report_stream_cb (const char *location, char ** data, int *len)
 
     if (!ok)
     {
+        SCM captured = scm_c_eval_string ("gnc:last-captured-error");
+        gchar *captured_str = gnc_scm_to_utf8_string(captured);
+
         *data = g_strdup_printf ("<html><body><h3>%s</h3>"
-                                 "<p>%s</p></body></html>",
+                                 "<p>%s</p><pre>%s</pre></body></html>",
                                  _("Report error"),
-                                 _("An error occurred while running the report."));
+                                 _("An error occurred while running the report."),
+                                 captured_str);
+
+        g_free (captured_str);
 
         /* Make sure the progress bar is finished, which will also
            make the GUI sensitive again. Easier to do this via guile
diff --git a/libgnucash/app-utils/c-interface.scm b/libgnucash/app-utils/c-interface.scm
index 8dba2b985..8c0b74b46 100644
--- a/libgnucash/app-utils/c-interface.scm
+++ b/libgnucash/app-utils/c-interface.scm
@@ -63,14 +63,17 @@
 (define (gnc:backtrace-if-exception proc . args)
   (let* ((apply-result (gnc:apply-with-error-handling proc args))
          (result (car apply-result))
-         (error (cadr apply-result)))
+         (captured-error (cadr apply-result)))
     (cond
-     (error
-      (display error (current-error-port))
+     (captured-error
+      (display captured-error (current-error-port))
+      (set! gnc:last-captured-error (gnc:html-string-sanitize captured-error))
       (when (defined? 'gnc:warn)
-        (gnc:warn error)))
+        (gnc:warn captured-error)))
      (else result))))
 
+(define-public gnc:last-captured-error "")
+
 ;; This database can be used to store and retrieve translatable
 ;; strings. Strings that are returned by the lookup function are
 ;; translated with gettext.

commit a259ba4a3e26b4b50ba911f42a40087440a5d60d
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sun Sep 22 21:17:40 2019 +0800

    [utilities] move gnc:html-string-sanitize to utilities.scm

diff --git a/gnucash/report/report-system/html-utilities.scm b/gnucash/report/report-system/html-utilities.scm
index e2b5d5934..5f9ab1ebb 100644
--- a/gnucash/report/report-system/html-utilities.scm
+++ b/gnucash/report/report-system/html-utilities.scm
@@ -870,18 +870,5 @@
           "<link rel=\"stylesheet\" type=\"text/css\" href=\"file:///~a\" />\n"
           (gnc-path-find-localized-html-file file)))
 
-;; function to sanitize strings prior to sending to html
-(define (gnc:html-string-sanitize str)
-  (with-output-to-string
-    (lambda ()
-      (string-for-each
-       (lambda (c)
-         (display
-          (case c
-            ((#\&) "&")
-            ((#\<) "<")
-            ((#\>) ">")
-            (else c))))
-       str))))
 
 
diff --git a/gnucash/report/report-system/report-system.scm b/gnucash/report/report-system/report-system.scm
index 4c2dd8b92..ceee70e11 100644
--- a/gnucash/report/report-system/report-system.scm
+++ b/gnucash/report/report-system/report-system.scm
@@ -122,7 +122,6 @@
 (export gnc:html-make-options-link)
 (export gnc:html-js-include)
 (export gnc:html-css-include)
-(export gnc:html-string-sanitize)
 
 ;; report.scm
 (export gnc:menuname-reports)
diff --git a/gnucash/report/report-system/test/test-html-utilities-srfi64.scm b/gnucash/report/report-system/test/test-html-utilities-srfi64.scm
index b973a44e9..c722a692b 100644
--- a/gnucash/report/report-system/test/test-html-utilities-srfi64.scm
+++ b/gnucash/report/report-system/test/test-html-utilities-srfi64.scm
@@ -12,44 +12,9 @@
 (define (run-test)
   (test-runner-factory gnc:test-runner)
   (test-begin "test-html-utilities-srfi64.scm")
-  (test-gnc:html-string-sanitize)
   (test-gnc:assign-colors)
   (test-end "test-html-utilities-srfi64.scm"))
 
-(define (test-gnc:html-string-sanitize)
-  (test-begin "gnc:html-string-sanitize")
-  (test-equal "null test"
-              "abc"
-              (gnc:html-string-sanitize "abc"))
-
-  (test-equal "sanitize ©"
-              "&copy;"
-              (gnc:html-string-sanitize "©"))
-
-  (if (not (string=? (with-output-to-string (lambda () (display "🎃"))) "🎃"))
-      (test-skip 2))
-  (test-equal "emoji unchanged"
-              "🎃"
-              (gnc:html-string-sanitize "🎃"))
-
-  (test-equal "complex string"
-              "Smiley:\"🙂\" something"
-              (gnc:html-string-sanitize "Smiley:\"🙂\" something"))
-
-  (test-equal "sanitize <b>bold tags</b>"
-              "<b>bold tags</b>"
-              (gnc:html-string-sanitize "<b>bold tags</b>"))
-
-  (test-equal "quotes are unchanged for html"
-              "\""
-              (gnc:html-string-sanitize "\""))
-
-  (test-equal "backslash is unchanged for html"
-              "\\"
-              (gnc:html-string-sanitize "\\"))
-
-  (test-end "gnc:html-string-sanitize"))
-
 (define (test-gnc:assign-colors)
   (test-begin "test-gnc:assign-colors")
   (test-equal "assign-colors can request many colors"
diff --git a/libgnucash/scm/test/test-libgnucash-scm-utilities.scm b/libgnucash/scm/test/test-libgnucash-scm-utilities.scm
index 50903c431..2f5b1a295 100644
--- a/libgnucash/scm/test/test-libgnucash-scm-utilities.scm
+++ b/libgnucash/scm/test/test-libgnucash-scm-utilities.scm
@@ -10,6 +10,7 @@
   (test-traverse-vec)
   (test-substring-replace)
   (test-sort-and-delete-duplicates)
+  (test-gnc:html-string-sanitize)
   (test-gnc:list-flatten)
   (test-begin "test-libgnucash-scm-utilities.scm"))
 
@@ -89,6 +90,40 @@
     (sort-and-delete-duplicates '(3 1 2) <))
   (test-end "sort-and-delete-duplicates"))
 
+(define (test-gnc:html-string-sanitize)
+  (test-begin "gnc:html-string-sanitize")
+  (test-equal "null test"
+              "abc"
+              (gnc:html-string-sanitize "abc"))
+
+  (test-equal "sanitize ©"
+              "&copy;"
+              (gnc:html-string-sanitize "©"))
+
+  (if (not (string=? (with-output-to-string (lambda () (display "🎃"))) "🎃"))
+      (test-skip 2))
+  (test-equal "emoji unchanged"
+              "🎃"
+              (gnc:html-string-sanitize "🎃"))
+
+  (test-equal "complex string"
+              "Smiley:\"🙂\" something"
+              (gnc:html-string-sanitize "Smiley:\"🙂\" something"))
+
+  (test-equal "sanitize <b>bold tags</b>"
+              "<b>bold tags</b>"
+              (gnc:html-string-sanitize "<b>bold tags</b>"))
+
+  (test-equal "quotes are unchanged for html"
+              "\""
+              (gnc:html-string-sanitize "\""))
+
+  (test-equal "backslash is unchanged for html"
+              "\\"
+              (gnc:html-string-sanitize "\\"))
+
+  (test-end "gnc:html-string-sanitize"))
+
 (define (test-gnc:list-flatten)
   (test-equal "gnc:list-flatten null"
     '()
diff --git a/libgnucash/scm/utilities.scm b/libgnucash/scm/utilities.scm
index 574097558..4bdc61ed8 100644
--- a/libgnucash/scm/utilities.scm
+++ b/libgnucash/scm/utilities.scm
@@ -172,6 +172,23 @@
    s1 s2 s3 0 (string-length s1) (max 0 (1- start))
    (and (positive? end-after) (+ (max 0 (1- start)) (1- end-after)))))
 
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+;; function to sanitize strings. the resulting string can be safely
+;; added to html.
+;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
+(define-public (gnc:html-string-sanitize str)
+  (with-output-to-string
+    (lambda ()
+      (string-for-each
+       (lambda (c)
+         (display
+          (case c
+            ((#\&) "&")
+            ((#\<) "<")
+            ((#\>) ">")
+            (else c))))
+       str))))
+
 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
 ;; avoid using strftime, still broken in guile-2.2. see explanation at
 ;; https://lists.gnu.org/archive/html/bug-guile/2019-05/msg00003.html



Summary of changes:
 gnucash/report/report-gnome/window-report.c        | 10 +++++--
 gnucash/report/report-system/html-utilities.scm    | 13 --------
 gnucash/report/report-system/report-system.scm     |  1 -
 .../test/test-html-utilities-srfi64.scm            | 35 ----------------------
 libgnucash/app-utils/c-interface.scm               | 11 ++++---
 .../scm/test/test-libgnucash-scm-utilities.scm     | 35 ++++++++++++++++++++++
 libgnucash/scm/utilities.scm                       | 17 +++++++++++
 7 files changed, 67 insertions(+), 55 deletions(-)



More information about the gnucash-changes mailing list