Skip to content

Commit 28fac9c

Browse files
plexusbbatsov
authored andcommitted
Sideloader: no line breaks in base64 content
Currently we are sending sideloaded resources as line-wrapped base64. The extra newlines confuse the nREPL sideloader, turning the result into binary garbage. I think in this case we should be both more conservative in what we send (this patch) and more lenient in what we receive (nREPL should sanitize the input and drop any characters that aren't valid base64).
1 parent 60d0e54 commit 28fac9c

File tree

2 files changed

+43
-1
lines changed

2 files changed

+43
-1
lines changed

cider-eval.el

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ When invoked with a prefix ARG the command doesn't prompt for confirmation."
196196
(let ((file (expand-file-name file cider-sideloader-dir)))
197197
(if (file-exists-p file)
198198
(with-current-buffer (find-file-noselect file)
199-
(base64-encode-string (substring-no-properties (buffer-string))))
199+
(base64-encode-string (substring-no-properties (buffer-string)) 'no-line-breaks))
200200
;; if we can't find the file we should return an empty string
201201
(base64-encode-string ""))))
202202

test/cider-eval-test.el

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
;;; cider-eval-tests.el
2+
3+
;; Copyright © 2012-2021 Arne Brasseur
4+
5+
;; Author: Arne Brasseur
6+
7+
;; This file is NOT part of GNU Emacs.
8+
9+
;; This program is free software: you can redistribute it and/or
10+
;; modify it under the terms of the GNU General Public License as
11+
;; published by the Free Software Foundation, either version 3 of the
12+
;; License, or (at your option) any later version.
13+
;;
14+
;; This program is distributed in the hope that it will be useful, but
15+
;; WITHOUT ANY WARRANTY; without even the implied warranty of
16+
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17+
;; General Public License for more details.
18+
;;
19+
;; You should have received a copy of the GNU General Public License
20+
;; along with this program. If not, see `http://www.gnu.org/licenses/'.
21+
22+
;;; Commentary:
23+
24+
;; This file is part of CIDER
25+
26+
;;; Code:
27+
28+
(require 'buttercup)
29+
(require 'cider-eval)
30+
31+
(describe "cider-provide-file"
32+
(it "returns an empty string when the file is not found"
33+
(expect (cider-provide-file "abc.clj") :to-equal ""))
34+
(it "base64 encodes without newlines"
35+
(let ((cider-sideloader-dir "/tmp")
36+
(default-directory "/tmp")
37+
(filename (make-temp-file "abc.clj")))
38+
(with-temp-file filename
39+
(dotimes (_ 60) (insert "x")))
40+
(expect (cider-provide-file filename) :not :to-match "\n"))))
41+
42+
(provide 'cider-eval-tests)

0 commit comments

Comments
 (0)