GNOME Bugzilla – Bug 727130
Gnucash crashes on saving report with Newline in Report Name
Last modified: 2018-06-29 23:28:48 UTC
After pasting a string containing a newline character into the Report Name field of the report options, applying the report options and clicking on the Save (floppy disk) icon in the report toolbar, Gnucash terminates without any visible message. Presumably, the string value is not being sanitized before further processing during the save action. Incidentally, the report name appears in the page tab split (i.e., with the newline displayed), while the title displayed within the report itself has no newline evident.
I can confirm this bug for GnuCash 2.6.2. with Guile 1.8. Tried it with the Income Statement report. This is from the gnucash trace: Backtrace: In unknown file: ?: 0* [gnc:report-to-template-new #] In /opt/gnucash-2.6.2/share/gnucash/scm/report.scm: 686: 1* [gnc:report-to-template # #f] 647: 2 (let* (# # # #) (if # # #f)) 655: 3* [eval-string ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; Options for saved report \"new line\", based on template \"0b81a3bdfd504aff849ec2e8630524bc\" (let () (define (options-gen) (let ((options (gnc:report-template-new-options/report-guid \"0b81a3bdfd504aff849ec2e8630524bc\" \"Income Statement\"))) ; Section: Entries ; Section: Display ; Section: Commodities ; Section: Accounts ; Section: General (let ((option (gnc:lookup-option options \"General\" \"Report name\"))) ((lambda (option) (if option ((gnc:option-setter option) \"new line\"))) option)) options)) (gnc:define-report 'version 1 'name \"new line\" 'report-guid \"feb0491628496531e1976a1488ae0d18\" 'parent-type \"0b81a3bdfd504aff849ec2e8630524bc\" 'options-generator options-gen 'menu-path (list gnc:menuname-custom) 'renderer (gnc:report-template-renderer/report-guid \"0b81a3bdfd504aff849ec2e8630524bc\" \"Income Statement\"))) "] /opt/gnucash-2.6.2/share/gnucash/scm/report.scm:655:23: In procedure eval-string in expression (eval-string saved-form): /opt/gnucash-2.6.2/share/gnucash/scm/report.scm:655:23: Unbound variable: line Anybody with permission, please set this report into status NEW.
The problem occurs during the format expression in report.scm function (gnc:report-template-serialize-internal name type templ-name options guid): (format #f ";; Options for saved report ~S, based on template ~S\n" name type) Here the report name is written into a comment including the line break, and a comment is not supposed to be broken into several lines. Once you comment out the lines 569 & 570 in report.scm all works fine again. (just tried it out: saves fine, and you can load the saved configuration fine) So one solution is to manipulate the name in this line before it is put into the string formater and eliminate the whitespace characters specifically at this point. On the other: Should whitespace characters in general be prohibited in a report title? INFO NEEDED
@Carsten: Thanks for looking into this. I forgot to mention that this issue can result in data loss (not only from the unsaved report configuration, but also from any unsaved transactions). Ordinarily, I would have marked it a higher priority, but it seems like an unusual use case. "Should whitespace characters in general be prohibited in a report title?" No, since the report title is displayed in the report itself. However, I would recommend replacing non-printing whitespace characters (tabs, newlines, hard spaces) with regular spaces as soon as the user input is processed by the dialog, and stripping any other non-printing characters. This would seem to cover a variety of possible issues, with minimal impact.
Created attachment 273280 [details] [review] patch to be applied on top of GnuCash 2.6.2 I propose to make use of the glib function g_strescape(). It makes the non-printable sequences visible by translating e.g. newline to "\n" and adds it to the string. With that the use will immediately become aware that there where escape sequences in the new title when looking at the report tab, and can then decide to do necessary updates manually afterwards, or just leave it as it is. With g_strcompress() the translation can be reverted back, for the case that the escape sequences shall be saved in the title as string for possible later use. See also the proposed patch attached.
@Carsten: Your approach seems quite reasonable. Thanks.
Comment on attachment 273280 [details] [review] patch to be applied on top of GnuCash 2.6.2 That was a clever idea! I have committed the patch as https://github.com/Gnucash/gnucash/commit/c9b5a81b083968695723fa4a215a7dba591c7a05 Thank you very much !
This problem has been fixed in our software repository. The fix will go into the next software release. Thank you for your bug report.
Actually a very bad idea. g_strescape not only escapes non-printable characters, it escapes all non-ascii characters as well, totally hosing i18n on this field, causing bug 760711. Amazing that it took almost two years for anyone to notice!
Reassign version to 2.4.x so that individual 2.4 versions can be retired.
GnuCash bug tracking has moved to a new Bugzilla host. This bug has been copied to https://bugs.gnucash.org/show_bug.cgi?id=727130. Please update any external references or bookmarks.