mirror of https://github.com/Gnucash/gnucash
Merge branch 'maint-string-html-escape' of https://github.com/christopherlam/gnucash into maint
commit
3e41bb011d
@ -1,44 +0,0 @@
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
;; This program is free software; you can redistribute it and/or
|
||||
;; modify it under the terms of the GNU General Public License as
|
||||
;; published by the Free Software Foundation; either version 2 of
|
||||
;; the License, or (at your option) any later version.
|
||||
;;
|
||||
;; This program is distributed in the hope that it will be useful,
|
||||
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
;; GNU General Public License for more details.
|
||||
;;
|
||||
;; You should have received a copy of the GNU General Public License
|
||||
;; along with this program; if not, contact:
|
||||
;;
|
||||
;; Free Software Foundation Voice: +1-617-542-5942
|
||||
;; 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
|
||||
;; Boston, MA 02110-1301, USA gnu@gnu.org
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
|
||||
(use-modules (gnucash core-utils))
|
||||
|
||||
(define (gnc:html-js-include file)
|
||||
(string-append
|
||||
"<script language=\"javascript\" type=\"text/javascript\" src=\"file:///"
|
||||
(gnc-path-find-localized-html-file file)
|
||||
"\"></script>\n"
|
||||
))
|
||||
|
||||
(define (gnc:html-css-include file)
|
||||
(string-append
|
||||
"<link rel=\"stylesheet\" type=\"text/css\" href=\"file:///"
|
||||
(gnc-path-find-localized-html-file file)
|
||||
"\" />\n"
|
||||
))
|
||||
|
||||
(define (jqplot-escape-string s1)
|
||||
;; Escape single and double quotes and backslashes
|
||||
(set! s1 (regexp-substitute/global #f "\\\\" s1 'pre "\\\\" 'post))
|
||||
(set! s1 (regexp-substitute/global #f "'" s1 'pre "\\'" 'post))
|
||||
(set! s1 (regexp-substitute/global #f "\"" s1 'pre "\\\"" 'post))
|
||||
;; Escape HTML special characters
|
||||
(set! s1 (regexp-substitute/global #f "&" s1 'pre "&" 'post))
|
||||
(set! s1 (regexp-substitute/global #f "<" s1 'pre "<" 'post))
|
||||
(regexp-substitute/global #f ">" s1 'pre ">" 'post))
|
||||
@ -0,0 +1,74 @@
|
||||
(use-modules (gnucash gnc-module))
|
||||
|
||||
(gnc:module-begin-syntax (gnc:module-load "gnucash/app-utils" 0))
|
||||
(gnc:module-begin-syntax (gnc:module-load "gnucash/report/report-system" 0))
|
||||
|
||||
(use-modules (gnucash engine test test-extras))
|
||||
(use-modules (gnucash report report-system test test-extras))
|
||||
(use-modules (gnucash report report-system))
|
||||
(use-modules (srfi srfi-64))
|
||||
|
||||
(define (test-runner)
|
||||
(let ((runner (test-runner-null))
|
||||
(num-passed 0)
|
||||
(num-failed 0))
|
||||
(test-runner-on-test-end! runner
|
||||
(lambda (runner)
|
||||
(format #t "[~a] line:~a, test: ~a\n"
|
||||
(test-result-ref runner 'result-kind)
|
||||
(test-result-ref runner 'source-line)
|
||||
(test-runner-test-name runner))
|
||||
(case (test-result-kind runner)
|
||||
((pass xpass) (set! num-passed (1+ num-passed)))
|
||||
((fail xfail)
|
||||
(if (test-result-ref runner 'expected-value)
|
||||
(format #t "~a\n -> expected: ~s\n -> obtained: ~s\n"
|
||||
(string-join (test-runner-group-path runner) "/")
|
||||
(test-result-ref runner 'expected-value)
|
||||
(test-result-ref runner 'actual-value)))
|
||||
(set! num-failed (1+ num-failed)))
|
||||
(else #t))))
|
||||
(test-runner-on-final! runner
|
||||
(lambda (runner)
|
||||
(format #t "Source:~a\npass = ~a, fail = ~a\n"
|
||||
(test-result-ref runner 'source-file) num-passed num-failed)
|
||||
(zero? num-failed)))
|
||||
runner))
|
||||
|
||||
(define (run-test)
|
||||
(test-runner-factory test-runner)
|
||||
(test-begin "test-html-utilities-srfi64.scm")
|
||||
(test-gnc:html-string-sanitize)
|
||||
(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 "©"))
|
||||
|
||||
(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"))
|
||||
Loading…
Reference in new issue