From mboxrd@z Thu Jan 1 00:00:00 1970
Path: news.gmane.org!.POSTED!not-for-mail
From: Philipp Stephani
Newsgroups: gmane.emacs.bugs
Subject: bug#25951: [PATCH] Fix quoted files for 'verify-visited-file-modtime'
Date: Sat, 29 Apr 2017 13:49:37 +0200
Message-ID: <20170429114937.34649-1-phst@google.com>
References:
NNTP-Posting-Host: blaine.gmane.org
X-Trace: blaine.gmane.org 1493466673 29750 195.159.176.226 (29 Apr 2017 11:51:13 GMT)
X-Complaints-To: usenet@blaine.gmane.org
NNTP-Posting-Date: Sat, 29 Apr 2017 11:51:13 +0000 (UTC)
Cc: Philipp Stephani
To: 25951@debbugs.gnu.org, npostavs@users.sourceforge.net
Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Apr 29 13:51:08 2017
Return-path:
Envelope-to: geb-bug-gnu-emacs@m.gmane.org
Original-Received: from lists.gnu.org ([208.118.235.17])
by blaine.gmane.org with esmtp (Exim 4.84_2)
(envelope-from )
id 1d4Qu3-0007Y1-Cq
for geb-bug-gnu-emacs@m.gmane.org; Sat, 29 Apr 2017 13:51:07 +0200
Original-Received: from localhost ([::1]:40734 helo=lists.gnu.org)
by lists.gnu.org with esmtp (Exim 4.71)
(envelope-from )
id 1d4Qu7-0004Sv-Ib
for geb-bug-gnu-emacs@m.gmane.org; Sat, 29 Apr 2017 07:51:11 -0400
Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:58677)
by lists.gnu.org with esmtp (Exim 4.71)
(envelope-from ) id 1d4Qu1-0004So-Pz
for bug-gnu-emacs@gnu.org; Sat, 29 Apr 2017 07:51:07 -0400
Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71)
(envelope-from ) id 1d4Qty-0006e3-N9
for bug-gnu-emacs@gnu.org; Sat, 29 Apr 2017 07:51:05 -0400
Original-Received: from debbugs.gnu.org ([208.118.235.43]:47413)
by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16)
(Exim 4.71) (envelope-from )
id 1d4Qty-0006dx-Ji
for bug-gnu-emacs@gnu.org; Sat, 29 Apr 2017 07:51:02 -0400
Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2)
(envelope-from ) id 1d4Qty-0008GH-7u
for bug-gnu-emacs@gnu.org; Sat, 29 Apr 2017 07:51:02 -0400
X-Loop: help-debbugs@gnu.org
Resent-From: Philipp Stephani
Original-Sender: "Debbugs-submit"
Resent-CC: bug-gnu-emacs@gnu.org
Resent-Date: Sat, 29 Apr 2017 11:51:02 +0000
Resent-Message-ID:
Resent-Sender: help-debbugs@gnu.org
X-GNU-PR-Message: followup 25951
X-GNU-PR-Package: emacs
X-GNU-PR-Keywords:
Original-Received: via spool by 25951-submit@debbugs.gnu.org id=B25951.149346660231689
(code B ref 25951); Sat, 29 Apr 2017 11:51:02 +0000
Original-Received: (at 25951) by debbugs.gnu.org; 29 Apr 2017 11:50:02 +0000
Original-Received: from localhost ([127.0.0.1]:45610 helo=debbugs.gnu.org)
by debbugs.gnu.org with esmtp (Exim 4.84_2)
(envelope-from )
id 1d4Qsz-0008F3-U8
for submit@debbugs.gnu.org; Sat, 29 Apr 2017 07:50:02 -0400
Original-Received: from mail-wr0-f194.google.com ([209.85.128.194]:35582)
by debbugs.gnu.org with esmtp (Exim 4.84_2)
(envelope-from ) id 1d4Qsy-0008EU-Ei
for 25951@debbugs.gnu.org; Sat, 29 Apr 2017 07:50:00 -0400
Original-Received: by mail-wr0-f194.google.com with SMTP id g12so9500846wrg.2
for <25951@debbugs.gnu.org>; Sat, 29 Apr 2017 04:50:00 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;
h=from:to:cc:subject:date:message-id:in-reply-to:references;
bh=kcKL73ejY6EbBgQXycffhsXDWi0nS9S/MfHA1QW0aI8=;
b=IrynMDm+DfnNFj0k3k3YQRy5NteRIk+mu/Ik3ea+6zylNVYLyLsgk1rAYy9sET1JWK
MK/QnlSWG2NynR0okSsyKoxQXKHIqP4ZyEb9PV1wrfyWWMtEF2jmqia1CX/wGNeYQxCQ
SA2cXXY5y/cjIM2yh1F1skILt7ChkXMLVQfuOM8D91nsD/4mOVuZezcH8y1EOyX/Ne77
44Fy+DkMYZDLRWvc9yUcNf2WoDYFbLS9Sldu6LCvejSNWY9FGDnPErdTfJ2y2W27SN8i
NJ+35CByoiJoDrqpcTMrX+8MJQhz3dSxc73MPECFnq+T4lS9JqW9nZ/WsRv0Ua04ZfEq
HZrw==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
d=1e100.net; s=20161025;
h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to
:references;
bh=kcKL73ejY6EbBgQXycffhsXDWi0nS9S/MfHA1QW0aI8=;
b=sFSKz9nd9UdHK7lz5zIOuM1BsaMom9AUzf+1OPG3j1HMSzDBZFtbR4GCgFtH5PxVlh
LGVbrjyV2Iu8vGzftDJxDOVQpydLOgI8kyFw/4bzFrr49IWYD+Jo9I5Q6KIKXlcydPHC
8bPxT0o58qCiOnT6orxZJRAsRlkRDF+92GmKcaI4sASLwbvRHR1qKf010r4u6/9530n+
luF33PxP+pywxY0kPb0SuSD+nqzyQrZmsE5yVak75yjw8kg1Kody6u4tajcXLRU6jzfP
UyyVcmIMqAnhvslbmndRNCygKLkMkmkVUxD20wHk49NpKwd/ra+vdG9YMlsVNqiTJKbP
mpSg==
X-Gm-Message-State: AN3rC/6/+ZlVCC+Cuz/pI9zvzrT3UFu0SQUqZwK3NjDP+/hUCKCzkQwI
jzNZFGXL/PcN4w==
X-Received: by 10.223.183.12 with SMTP id l12mr10149273wre.191.1493466594620;
Sat, 29 Apr 2017 04:49:54 -0700 (PDT)
Original-Received: from p.cm.cablesurf.de (46.128.198.151.dynamic.cablesurf.de.
[46.128.198.151])
by smtp.gmail.com with ESMTPSA id 25sm9801104wrz.8.2017.04.29.04.49.52
(version=TLS1 cipher=AES128-SHA bits=128/128);
Sat, 29 Apr 2017 04:49:53 -0700 (PDT)
X-Google-Original-From: Philipp Stephani
X-Mailer: git-send-email 2.12.2
In-Reply-To:
X-BeenThere: debbugs-submit@debbugs.gnu.org
X-Mailman-Version: 2.1.18
Precedence: list
X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic]
X-Received-From: 208.118.235.43
X-BeenThere: bug-gnu-emacs@gnu.org
List-Id: "Bug reports for GNU Emacs,
the Swiss army knife of text editors"
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org
Original-Sender: "bug-gnu-emacs"
Xref: news.gmane.org gmane.emacs.bugs:132101
Archived-At:
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