diff --git a/gnucash/report/report-system/html-utilities.scm b/gnucash/report/report-system/html-utilities.scm
index e2b5d5934a..5f9ab1ebbb 100644
--- a/gnucash/report/report-system/html-utilities.scm
+++ b/gnucash/report/report-system/html-utilities.scm
@@ -870,18 +870,5 @@
"\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 4c2dd8b925..ceee70e11b 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 b973a44e95..c722a692b9 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 ©"
- "©"
- (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 bold tags"
- "<b>bold tags</b>"
- (gnc:html-string-sanitize "bold tags"))
-
- (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 50903c4315..2f5b1a2951 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 ©"
+ "©"
+ (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 bold tags"
+ "<b>bold tags</b>"
+ (gnc:html-string-sanitize "bold tags"))
+
+ (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 574097558e..4bdc61ed85 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