From 19e268c0cbff870900c0923ae41c392ab4f42d0b Mon Sep 17 00:00:00 2001 From: Carlo Sciolla Date: Fri, 30 Aug 2019 22:54:26 +0200 Subject: [PATCH] Ensure base64 encoding happens after coding the string with UTF8 (#111) * Fixes #110 Ensure base64 encoding happens after coding the string with UTF8 * Avoid line breaks in base64 encoding --- plantuml-mode.el | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/plantuml-mode.el b/plantuml-mode.el index f45ff17..6165ada 100644 --- a/plantuml-mode.el +++ b/plantuml-mode.el @@ -406,13 +406,20 @@ Put the result into buffer BUF. Window is selected according to PREFIX: (error "PLANTUML Preview failed: %s" event)) (plantuml-update-preview-buffer prefix buf))))) +(defun plantuml-server-encode-url (string) + "Encode the string STRING into a URL suitable for PlantUML server interactions." + (let* ((coding-system (or buffer-file-coding-system + "utf8")) + (encoded-string (base64-encode-string (encode-coding-string string coding-system) t))) + (concat plantuml-server-url "/" plantuml-output-type "/-base64-" encoded-string))) + (defun plantuml-server-preview-string (prefix string buf) "Preview the diagram from STRING as rendered by the PlantUML server. Put the result into buffer BUF and place it according to PREFIX: - 4 (when prefixing the command with C-u) -> new window - 16 (when prefixing the command with C-u C-u) -> new frame. - else -> new buffer" - (let* ((url-request-location (concat plantuml-server-url "/" plantuml-output-type "/-base64-" (base64-encode-string string t)))) + (let* ((url-request-location (plantuml-server-encode-url string))) (save-current-buffer (save-match-data (url-retrieve url-request-location