bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

bug#25951: [PATCH] Fix quoted files for 'verify-visited-file-modtime'


From: Philipp Stephani
Subject: bug#25951: [PATCH] Fix quoted files for 'verify-visited-file-modtime'
Date: Sat, 29 Apr 2017 13:49:37 +0200

Fixes Bug#25951.

* lisp/files.el (file-name-non-special): Set the file name for the
correct buffer.

* test/lisp/files-tests.el (files-tests--file-name-non-special--buffers):
Add unit test.
---
 lisp/files.el            |  9 ++++++++-
 test/lisp/files-tests.el | 42 +++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 49 insertions(+), 2 deletions(-)

diff --git a/lisp/files.el b/lisp/files.el
index 6848818cad..2e9ab1aad1 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -28,6 +28,8 @@
 
 ;;; Code:
 
+(eval-when-compile (require 'cl-lib))
+
 (defvar font-lock-keywords)
 
 (defgroup backup nil
@@ -6987,7 +6989,12 @@ file-name-non-special
            (when (and visit buffer-file-name)
              (setq buffer-file-name (concat "/:" buffer-file-name))))))
       (`unquote-then-quote
-       (let ((buffer-file-name (substring buffer-file-name 2)))
+       (cl-letf* ((buffer (or (car arguments) (current-buffer)))
+                  ((buffer-local-value 'buffer-file-name buffer)
+                   (substring (buffer-file-name buffer) 2)))
+         ;; `unquote-then-quote' is only used for the
+         ;; `verify-visited-file-modtime' action, which takes a buffer
+         ;; as only optional argument.
          (apply operation arguments)))
       (_
        (apply operation arguments)))))
diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el
index 80bbeb1bc5..9c633198f1 100644
--- a/test/lisp/files-tests.el
+++ b/test/lisp/files-tests.el
@@ -1,4 +1,4 @@
-;;; files-tests.el --- tests for files.el.
+;;; files-tests.el --- tests for files.el.  -*- lexical-binding: t; -*-
 
 ;; Copyright (C) 2012-2017 Free Software Foundation, Inc.
 
@@ -20,6 +20,7 @@
 ;;; Code:
 
 (require 'ert)
+(require 'nadvice)
 
 ;; Set to t if the local variable was set, `query' if the query was
 ;; triggered.
@@ -251,5 +252,44 @@ files-test-bug-18141-file
                       (start-file-process "foo" nil "true"))))
   (should (eq (let ((default-directory "/:/")) (shell-command "true")) 0)))
 
+(ert-deftest files-tests--file-name-non-special--buffers ()
+  "Check that Bug#25951 is fixed.
+We call `verify-visited-file-modtime' on a buffer visiting a file
+with a quoted name.  We use two different variants: first with
+the buffer current and a nil argument, second passing the buffer
+object explicitly.  In both cases no error should be raised and
+the `file-name-non-special' handler for quoted file names should
+be invoked with the right arguments."
+  (with-temp-buffer
+    (let* ((buffer-file-name "/:/tmp/bug25951.txt")
+           (buffer-visiting-file (current-buffer))
+           (actual-args ())
+           (log (lambda (&rest args) (push args actual-args))))
+      (set-visited-file-modtime '(1 2 3 4))
+      (should (equal (find-file-name-handler buffer-file-name
+                                             #'verify-visited-file-modtime)
+                     #'file-name-non-special))
+      (advice-add #'file-name-non-special :before log)
+      (unwind-protect
+          (progn
+            (should (stringp buffer-file-name))
+            ;; This should call the file name handler with the right
+            ;; buffer and not signal an error.  The file doesn't
+            ;; actually exist, so this should return nil.
+            (should-not (verify-visited-file-modtime))
+            (with-temp-buffer
+              (should (stringp (buffer-file-name buffer-visiting-file)))
+              ;; This should call the file name handler with the right
+              ;; buffer and not signal an error.  The file doesn't
+              ;; actually exist, so this should return nil.
+              (should-not (verify-visited-file-modtime buffer-visiting-file))))
+        (advice-remove #'file-name-non-special 'bug25951))
+      ;; Verify that the handler was actually called.  We called
+      ;; `verify-visited-file-modtime' twice, so both calls should be
+      ;; recorded in reverse order.
+      (should (equal actual-args
+                     `((verify-visited-file-modtime ,buffer-visiting-file)
+                       (verify-visited-file-modtime nil)))))))
+
 (provide 'files-tests)
 ;;; files-tests.el ends here
-- 
2.12.2






reply via email to

[Prev in Thread] Current Thread [Next in Thread]