Skip to content

Commit c43b727

Browse files
committed
Remove carriage returns when decoding strings
Fixes #1100.
1 parent 48c680e commit c43b727

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

nrepl-client.el

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,10 @@ object is a root list or dict."
500500
(progn (goto-char pos0)
501501
(cons :stub stack))
502502
(goto-char end)
503-
(cons nil (nrepl--push (buffer-substring-no-properties beg end)
504-
stack)))))
503+
;; normalise any platform-specific newlines
504+
(let* ((original (buffer-substring-no-properties beg end))
505+
(result (replace-regexp-in-string "\r" "" original)))
506+
(cons nil (nrepl--push result stack))))))
505507
;; integer
506508
((looking-at "i\\(-?[0-9]+\\)e")
507509
(goto-char (match-end 0))

test/nrepl-bencode-tests.el

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ If object is incomplete, return a decoded path."
2121
(ert-deftest test-nrepl-bdecode-string ()
2222
(should (equal '("spam") (nrepl-bdecode-string "4:spam"))))
2323

24+
(ert-deftest test-nrepl-bdecode-string-platform-specific-newlines ()
25+
(should (equal '("spam\n") (nrepl-bdecode-string "5:spam
26+
")))
27+
(should (equal '("spam\n") (nrepl-bdecode-string "6:spam
28+
"))))
29+
2430
(ert-deftest test-nrepl-bdecode-integer ()
2531
(should (equal '(3) (nrepl-bdecode-string "i3e"))))
2632

0 commit comments

Comments
 (0)