From 5717ccd1d405f108f3789e6a93912dec39d63e86 Mon Sep 17 00:00:00 2001 From: Tom Gillespie Date: Sun, 15 Aug 2021 16:06:29 -0700 Subject: [PATCH] Fix hack-local-variables for find-file-literally with dos encoding * lisp/files.el (hack-local-variables--find-variables): Update hack-local-variables--find-variables to remove spurious conversion of ?\^m to ?\n. * test/lisp/files-tests.el (files-tests-hack-local-literal-dos): Added test for calling hack-local-variables on files with dos encoding opened with find-file-literally and find-file. This fixes a bug where hack-local-variables would fail to find a matching suffix for local variables when files with dos line endings were opened literally using find-file-literally. The test for find-file and find-file-literally both succeed when the conversion is removed, and it is not clear that it was doing anything other than causing a bug matching suffix to local variable lines. --- lisp/files.el | 1 - test/lisp/files-tests.el | 16 ++++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lisp/files.el b/lisp/files.el index 875ac55316..b2c84cffaa 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -3947,7 +3947,6 @@ hack-local-variables--find-variables (with-temp-buffer (insert-buffer-substring thisbuf startpos endpos) (goto-char (point-min)) - (subst-char-in-region (point) (point-max) ?\^m ?\n) (while (not (eobp)) ;; Discard the prefix. (if (looking-at prefix) diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el index fb24b98595..e3c584dd28 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el @@ -164,6 +164,22 @@ files-tests-permanent-local-variables (hack-local-variables) (should (eq lexical-binding nil))))) +(ert-deftest files-tests-hack-local-literal-dos () + (let ((tempfile (make-temp-file "files-tests-test-hack-local-literal-dos" nil ".el"))) + (unwind-protect + (progn + (with-temp-buffer + (insert ";; -*- mode: Emacs-Lisp -*-\^m\n;; Local Variables:\^m\n;; lol: t\^m\n;; End:\^m\n") + (write-file tempfile)) + (with-current-buffer (find-file-literally tempfile) + (hack-local-variables) + (kill-buffer)) + (with-current-buffer (let (enable-local-variables) + (find-file tempfile)) + (hack-local-variables) + (kill-buffer))) + (delete-file tempfile)))) + (defvar files-test-bug-18141-file (ert-resource-file "files-bug18141.el.gz") "Test file for bug#18141.") -- 2.31.1