Skip to content

Commit 0bb92d1

Browse files
committed
[Fix #525] and clojure-emacs/cider-nrepl#25, bencode parser can handle nil
1 parent 206d292 commit 0bb92d1

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

nrepl-client.el

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,13 +198,15 @@ To be used for tooling calls (i.e. completion, eldoc, etc)")
198198
((looking-at "l")
199199
(goto-char (match-end 0))
200200
(let (result item)
201-
(while (setq item (nrepl-bdecode-buffer))
201+
;; check for the end sentinel, setq returns the value
202+
(while (not (eq :end (setq item (nrepl-bdecode-buffer))))
202203
(setq result (cons item result)))
203204
(nreverse result)))
204205
((looking-at "d")
205206
(goto-char (match-end 0))
206207
(let (dict key item)
207-
(while (setq item (nrepl-bdecode-buffer))
208+
;; check for the end sentinel, setq returns the value
209+
(while (not (eq :end (setq item (nrepl-bdecode-buffer))))
208210
(if key
209211
(setq dict (cons (cons key item) dict)
210212
key nil)
@@ -214,7 +216,12 @@ To be used for tooling calls (i.e. completion, eldoc, etc)")
214216
(cons 'dict (nreverse dict))))
215217
((looking-at "e")
216218
(goto-char (match-end 0))
217-
nil)
219+
;; This line used to return nil and checks above checked for
220+
;; falsiness to indicate the end of a list/dict, but that
221+
;; meant that nil/() was unable to pass through without
222+
;; shorting the algorithm. Now we return an :end keyword
223+
;; as a sentinel value and check for equality.
224+
:end)
218225
(t
219226
(error "Cannot decode object: %d" (point)))))
220227

test/nrepl-bencode-tests.el

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,3 +90,9 @@
9090
("status" "done")))
9191
(nrepl-decode
9292
"d2:id2:422:ns4:user7:session36:3f586403-ed47-4e4d-b8db-70522054f9715:value5:\"\"ed2:id2:427:session36:3f586403-ed47-4e4d-b8db-70522054f9716:statusl4:doneee"))))
93+
94+
(ert-deftest test-nrepl-decode-nils ()
95+
(should (equal '(("" nil (dict ("" . nil))))
96+
(nrepl-decode "l0:led0:leee")))
97+
(should (equal '(("" nil (dict ("" . 6))))
98+
(nrepl-decode "l0:led0:i6eee"))))

0 commit comments

Comments
 (0)