Skip to content

Commit

Permalink
Fix issues with online export.
Browse files Browse the repository at this point in the history
Sometimes we just didn't escape things properly. Use url-lib to handle
that for us, because we really shouldn't have to be doing stuff like
this manually.
  • Loading branch information
josteink committed Feb 13, 2016
1 parent b5e8ea0 commit 6909b4e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 4 deletions.
13 changes: 10 additions & 3 deletions wsd-core.el
Expand Up @@ -205,7 +205,7 @@ to the operating-system to open the local copy."
(message url))))

(defun wsd-browse-url (url)
"Open `URL' in a browser which can support image-formats not understood by emacs."
"Open `URL' in a browser which can support image-formats not understood by Emacs."

;; Some people have eww bound as the default-browser.
;;
Expand All @@ -219,12 +219,19 @@ to the operating-system to open the local copy."
(eww-browse-with-external-browser url)
(browse-url url)))

(defun wsd-get-diagram-online-url (message)
"Return the url to show `MESSAGE' online."
(let*
((encoded (url-build-query-string
`((m ,message))))
(url (concat wsd-base-url "?" encoded)))
url))

(defun wsd-show-diagram-online ()
"Show the current buffer on www.websequencediagrams.com."
(interactive)
(let* ((message (buffer-substring-no-properties (point-min) (point-max)))
(encoded (wsd-encode message))
(url (concat wsd-base-url "?m=" encoded)))
(url (wsd-get-diagram-online-url message)))
(browse-url url)))

(provide 'wsd-core)
Expand Down
2 changes: 1 addition & 1 deletion wsd-mode.el
Expand Up @@ -2,7 +2,7 @@

;; Author : Jostein Kjønigsen <jostein@gmail.com>
;; Created : December 2014
;; Modified : Februar 2016
;; Modified : February 2016
;; Version : 0.5.0
;; Keywords : wsd diagrams design process modelling uml
;; X-URL : https://github.com/josteink/wsd-mode
Expand Down
11 changes: 11 additions & 0 deletions wsd-tests.el
Expand Up @@ -173,6 +173,17 @@

(kill-buffer buffer)))

(ert-deftest document-contents-are-encoded-when-shown-online ()
(let* ((test-chars "\"#¤&/()+&<>")
(url-base (wsd-get-diagram-online-url ""))
(url (wsd-get-diagram-online-url test-chars))
(url-query (substring url (length url-base))))
(dolist (char (string-to-list test-chars))
;; (message (concat "Testing " (string char)))
(should (not (string-match-p
(regexp-quote (string char))
url-query))))))

;; (ert-deftest flycheck-errors-are-returned ()
;; (let* ((result (wsd-flycheck-parse-errors
;; 'wsd-mode-checker
Expand Down

0 comments on commit 6909b4e

Please sign in to comment.