branch: elpa/cider
commit 6f594176acef686e33361b24a8afe78dcdb3dade
Author: Bozhidar Batsov <[email protected]>
Commit: Bozhidar Batsov <[email protected]>
Don't treat a server notification as a format string
`nrepl-notify' passed the server-provided message straight to `message' as
its format string, so a stray `%' (e.g. "100% resolved") would misparse or
signal. Pass it as an argument instead.
---
lisp/nrepl-client.el | 4 +++-
test/nrepl-client-tests.el | 7 +++++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/lisp/nrepl-client.el b/lisp/nrepl-client.el
index e1bbb24bdf..0fd298b11b 100644
--- a/lisp/nrepl-client.el
+++ b/lisp/nrepl-client.el
@@ -773,7 +773,9 @@ Displays the notification via `message'."
(msg (if face
(propertize msg 'face face)
(format "%s: %s" (upcase type) msg))))
- (message msg)))
+ ;; MSG is server-provided, so pass it as an argument rather than as the
+ ;; format string - a stray `%' would otherwise misparse or error.
+ (message "%s" msg)))
(cl-defun nrepl-make-eval-handler (&key on-value on-stdout on-stderr on-done
on-ns on-status
diff --git a/test/nrepl-client-tests.el b/test/nrepl-client-tests.el
index c81a6d677f..5765ba1eab 100644
--- a/test/nrepl-client-tests.el
+++ b/test/nrepl-client-tests.el
@@ -547,3 +547,10 @@
(funcall (nrepl-make-response-handler 'shim-buf nil nil nil nil)
'(dict "id" "1" "status" ("eval-error"))))
(expect seen :to-be 'shim-buf))))
+
+(describe "nrepl-notify"
+ ;; The server controls the message text, so a `%' in it must not be treated
+ ;; as a format directive (which used to signal or misparse).
+ (it "does not treat a server message as a format string"
+ (expect (nrepl-notify "test %s and 100%" "warning") :not :to-throw)
+ (expect (nrepl-notify "raw 50% done" nil) :not :to-throw)))