Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…ser can handle nil
  • Loading branch information
gtrak committed Apr 8, 2014
1 parent 206d292 commit 0bb92d1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
13 changes: 10 additions & 3 deletions nrepl-client.el
Original file line number Diff line number Diff line change
Expand Up @@ -198,13 +198,15 @@ To be used for tooling calls (i.e. completion, eldoc, etc)")
((looking-at "l")
(goto-char (match-end 0))
(let (result item)
(while (setq item (nrepl-bdecode-buffer))
;; check for the end sentinel, setq returns the value
(while (not (eq :end (setq item (nrepl-bdecode-buffer))))
(setq result (cons item result)))
(nreverse result)))
((looking-at "d")
(goto-char (match-end 0))
(let (dict key item)
(while (setq item (nrepl-bdecode-buffer))
;; check for the end sentinel, setq returns the value
(while (not (eq :end (setq item (nrepl-bdecode-buffer))))
(if key
(setq dict (cons (cons key item) dict)
key nil)
Expand All @@ -214,7 +216,12 @@ To be used for tooling calls (i.e. completion, eldoc, etc)")
(cons 'dict (nreverse dict))))
((looking-at "e")
(goto-char (match-end 0))
nil)
;; This line used to return nil and checks above checked for
;; falsiness to indicate the end of a list/dict, but that
;; meant that nil/() was unable to pass through without
;; shorting the algorithm. Now we return an :end keyword
;; as a sentinel value and check for equality.
:end)
(t
(error "Cannot decode object: %d" (point)))))

Expand Down
6 changes: 6 additions & 0 deletions test/nrepl-bencode-tests.el
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,9 @@
("status" "done")))
(nrepl-decode
"d2:id2:422:ns4:user7:session36:3f586403-ed47-4e4d-b8db-70522054f9715:value5:\"\"ed2:id2:427:session36:3f586403-ed47-4e4d-b8db-70522054f9716:statusl4:doneee"))))

(ert-deftest test-nrepl-decode-nils ()
(should (equal '(("" nil (dict ("" . nil))))
(nrepl-decode "l0:led0:leee")))
(should (equal '(("" nil (dict ("" . 6))))
(nrepl-decode "l0:led0:i6eee"))))

0 comments on commit 0bb92d1

Please sign in to comment.