make-uri: Ensure correct number of slashes in file URI.

This commit is contained in:
John Ralls
2021-12-27 09:43:09 -08:00
parent b435ee60c0
commit b57f900401
2 changed files with 7 additions and 4 deletions

View File

@@ -413,11 +413,14 @@
(string->char-set ":/?#[]@") ;gen-delims
(string->char-set "-._~")))
;;path must be absolute. On Windows an absolute path begins with a
;;drive letter followed by a colon.
(define (make-uri path)
(string-append
"file://"
(uri-encode (gnc:substring-replace path "\\" "/")
(let ((uri-path (uri-encode (gnc:substring-replace path "\\" "/")
#:unescaped-chars unreserved-chars-rfc3986)))
(string-append
(if (char=? (string-ref uri-path 0) #\/) "file://" "file:///")
uri-path)))
(define (gnc:html-js-include file)
(format #f

View File

@@ -25,7 +25,7 @@
(test-begin "test-html-includes")
(test-equal "windows path into rfc3986 uri"
"file://C:/Program%20Files%20%28x86%29/gnucash/share/gnucash/chartjs/Chart.bundle.min.js"
"file:///C:/Program%20Files%20%28x86%29/gnucash/share/gnucash/chartjs/Chart.bundle.min.js"
(make-uri "C:\\Program Files (x86)\\gnucash/share\\gnucash\\chartjs/Chart.bundle.min.js"))
(test-end "test-html-includes"))