[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/reformatter 84cff54b08 72/81: Merge pull request #36 from
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/reformatter 84cff54b08 72/81: Merge pull request #36 from kenranunderscore/harden-temp-file-creation |
Date: |
Tue, 5 Sep 2023 04:03:39 -0400 (EDT) |
branch: elpa/reformatter
commit 84cff54b0873fcca6fc0314d7584284e86708e8d
Merge: 7c5452bf31 edf1c42de8
Author: Steve Purcell <steve@sanityinc.com>
Commit: GitHub <noreply@github.com>
Merge pull request #36 from kenranunderscore/harden-temp-file-creation
Handle slashes in names of created functions when creating temporary files
---
reformatter-tests.el | 14 +++++++++++++-
reformatter.el | 23 ++++++++++++++++-------
2 files changed, 29 insertions(+), 8 deletions(-)
diff --git a/reformatter-tests.el b/reformatter-tests.el
index 8eb99d2380..2878734eb9 100644
--- a/reformatter-tests.el
+++ b/reformatter-tests.el
@@ -55,6 +55,19 @@
(reformatter-tests-shfmt-tempfile-in-stdout-buffer)
(should (equal "[ foo ] && echo yes\n" (buffer-string)))))
+;; Same as `reformatter-tests-shfmt-tempfile-in-stdout', but with a
+;; slash in the symbol name.
+(reformatter-define reformatter-tests-tempfile/with-slash-in-symbol-name
+ :program "shfmt"
+ :stdin nil
+ :args (list input-file))
+
+(ert-deftest reformatter-tests-tempfile-with-slash-in-symbol-name ()
+ (with-temp-buffer
+ (insert "[ foo ] && echo yes\n")
+ (reformatter-tests-tempfile/with-slash-in-symbol-name-buffer)
+ (should (equal "[ foo ] && echo yes\n" (buffer-string)))))
+
;; Modify a file in place
(reformatter-define reformatter-tests-shfmt-in-place
:program "shfmt"
@@ -69,6 +82,5 @@
(should (equal "[ foo ] && echo yes\n" (buffer-string)))))
-
(provide 'reformatter-tests)
;;; reformatter-tests.el ends here
diff --git a/reformatter.el b/reformatter.el
index 6cb4136614..6faad76963 100644
--- a/reformatter.el
+++ b/reformatter.el
@@ -76,6 +76,13 @@
(require 'cl-lib))
(require 'ansi-color)
+(defun reformatter--make-temp-file (sym)
+ "Create a temporary file whose filename is based on SYM, but with
+slashes replaced by underscores. `make-temp-file' fails
+otherwise as it cannot create intermediate directories."
+ (make-temp-file
+ (replace-regexp-in-string "/" "_" (symbol-name sym))))
+
(defun reformatter--do-region (name beg end program args stdin stdout
input-file exit-code-success-p display-errors)
"Do the work of reformatter called NAME.
Reformats the current buffer's region from BEG to END using
@@ -89,8 +96,8 @@ the `reformatter-define' macro."
(string= (file-truename input-file)
(file-truename (buffer-file-name))))
(error "The reformatter must not operate on the current file in-place"))
- (let* ((stderr-file (make-temp-file (symbol-name name)))
- (stdout-file (make-temp-file (symbol-name name)))
+ (let* ((stderr-file (reformatter--make-temp-file name))
+ (stdout-file (reformatter--make-temp-file name))
;; Setting this coding system might not universally be
;; the best default, but was apparently necessary for
;; some hand-rolled reformatter functions that this
@@ -104,10 +111,10 @@ the `reformatter-define' macro."
(retcode
(condition-case e
(apply 'call-process program
- (when stdin input-file)
- (list (list :file stdout-file) stderr-file)
- nil
- args)
+ (when stdin input-file)
+ (list (list :file stdout-file) stderr-file)
+ nil
+ args)
(error e))))
(with-current-buffer error-buffer
(let ((inhibit-read-only t))
@@ -268,7 +275,9 @@ might use:
When called interactively, or with prefix argument
DISPLAY-ERRORS, shows a buffer if the formatting fails."
(interactive "rp")
- (let ((input-file ,(if input-file input-file `(make-temp-file
,(symbol-name name)))))
+ (let ((input-file ,(if input-file
+ input-file
+ `(reformatter--make-temp-file ',name))))
;; Evaluate args with input-file bound
(unwind-protect
(progn
- [nongnu] elpa/reformatter 394b3a6606 55/81: Add reformatter-temp-file-in-current-directory, (continued)
- [nongnu] elpa/reformatter 394b3a6606 55/81: Add reformatter-temp-file-in-current-directory, ELPA Syncer, 2023/09/05
- [nongnu] elpa/reformatter 576d339aa8 60/81: Add Emacs 27.2 to CI matrix, ELPA Syncer, 2023/09/05
- [nongnu] elpa/reformatter 19582a205e 62/81: Use Emacs > 21 define-minor-mode call convention, ELPA Syncer, 2023/09/05
- [nongnu] elpa/reformatter b57f5d4800 65/81: Merge pull request #33 from bcc32/display-call-process-signal-error-in-buffer, ELPA Syncer, 2023/09/05
- [nongnu] elpa/reformatter 7ba5486696 56/81: Clarify that extension does not include the dot, ELPA Syncer, 2023/09/05
- [nongnu] elpa/reformatter c9cf3f0227 80/81: Merge pull request #42 from purcell/dependabot/github_actions/actions/checkout-4, ELPA Syncer, 2023/09/05
- [nongnu] elpa/reformatter 6c4f35dd2b 81/81: Merge pull request #43 from purcell/dependabot/github_actions/cachix/install-nix-action-23, ELPA Syncer, 2023/09/05
- [nongnu] elpa/reformatter c1410f0c7a 75/81: chore(deps): bump cachix/install-nix-action from 12 to 22, ELPA Syncer, 2023/09/05
- [nongnu] elpa/reformatter edf1c42de8 71/81: Use -buffer suffix when calling reformatter in test, ELPA Syncer, 2023/09/05
- [nongnu] elpa/reformatter 1428ca9e42 70/81: Fix form quoting, and tabs, ELPA Syncer, 2023/09/05
- [nongnu] elpa/reformatter 84cff54b08 72/81: Merge pull request #36 from kenranunderscore/harden-temp-file-creation,
ELPA Syncer <=
- [nongnu] elpa/reformatter 1354f1b9b8 79/81: chore(deps): bump cachix/install-nix-action from 22 to 23, ELPA Syncer, 2023/09/05
- [nongnu] elpa/reformatter af39397957 44/81: Fix CI link, ELPA Syncer, 2023/09/05
- [nongnu] elpa/reformatter bfe3f1c6ec 77/81: Release 0.7, ELPA Syncer, 2023/09/05
- [nongnu] elpa/reformatter f454b179ab 73/81: Add Emacs 28.2 to CI, cut down size of matrix, ELPA Syncer, 2023/09/05