From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Philipp Stephani Newsgroups: gmane.emacs.devel Subject: [PATCH] Fix quoted files for 'verify-visited-file-modtime' Date: Sat, 29 Apr 2017 14:20:27 +0200 Message-ID: <20170429122027.39318-1-phst@google.com> References: <83fugvpw24.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1493468456 17361 195.159.176.226 (29 Apr 2017 12:20:56 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 29 Apr 2017 12:20:56 +0000 (UTC) Cc: Philipp Stephani To: 25951@debbugs.gnu.org, npostavs@users.sourceforge.net, emacs-devel@gnu.org, eliz@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sat Apr 29 14:20:48 2017 Return-path: Envelope-to: ged-emacs-devel@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 1d4RMm-0004K9-EP for ged-emacs-devel@m.gmane.org; Sat, 29 Apr 2017 14:20:48 +0200 Original-Received: from localhost ([::1]:41033 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d4RMs-0000nE-6t for ged-emacs-devel@m.gmane.org; Sat, 29 Apr 2017 08:20:54 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34576) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d4RMj-0000n4-Gf for emacs-devel@gnu.org; Sat, 29 Apr 2017 08:20:46 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d4RMg-0005DL-8b for emacs-devel@gnu.org; Sat, 29 Apr 2017 08:20:45 -0400 Original-Received: from mail-wr0-x243.google.com ([2a00:1450:400c:c0c::243]:35025) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d4RMf-0005C1-U6; Sat, 29 Apr 2017 08:20:42 -0400 Original-Received: by mail-wr0-x243.google.com with SMTP id g12so9552308wrg.2; Sat, 29 Apr 2017 05:20:41 -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=sxYOFyUjgKNtTGYvALYXt1o7irpgDeOTrkwPPlqkRhI=; b=q8aBYWeveiNPflj/H9JlYJR96mzfYOYExy4VEv1cp/ROj86p3SwX466+UhnDsjv6Z9 fd1vR+L6l+ZoWmLjt7QQ+TPdoibFLOY8QpDUVYqrQhjuYW562e6dj9jY63wmejxNR94w nmKxDiNnJ7lI6KiLtk74Tp3UGuwZ/pb/Mrg81XPtwEIBtJSmCi7jG8CuPc50qg+qqOWK vvkzxOQIqr+M6Ft3TS15ygIDDkMF/wmlnltkYpvdpUf7yDBsBNCtsZKT8A8Xnv0XhQjq F4i20T4iTMTz0PoimkZE4bCU44mJ2K0WOV7tkldbelFkp432g1Yt7ddtz5rPMOhwEkIU lnOQ== 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=sxYOFyUjgKNtTGYvALYXt1o7irpgDeOTrkwPPlqkRhI=; b=I5XJxcKjxeK+nJjPrvXZ4m1z31sQv0MeOAjHrUmr0F40jfFkpqq1X4RH78QoAh/vrv iqsq/uOS4nA5Qr2lbaK9uEwMJp0L6FJ/4sKGMa4DEcIB4vY65r6hr73AdfPpchdQHZiP M7XRYA4IWAzlwkWhggcffOgPEQOczF05fagsMyUb6xA/yxl+M2NSv3DfaRdzffRDDdke U2qf1cVjCjmF7UdPVRDKVD9gLSYrs8gJXt36Grkzv7G8P905CRo1vgdxqjMuRftaExRp 2kCV9OLycOuz58dcdBTD40cxqFzuB2g7TAzdGyY5W1iO4o7qN4JRzggcs2wxBp6pBtDq 0PQg== X-Gm-Message-State: AN3rC/6m7MCIIFuYABMoIexEU4azvaGKVMRGN/wYEmhrMqhhbpBnLFGr TcOSDTRoCXEnlJlWfyA= X-Received: by 10.223.164.153 with SMTP id g25mr10345528wrb.103.1493468440619; Sat, 29 Apr 2017 05:20:40 -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 u200sm924079wmd.16.2017.04.29.05.20.39 (version=TLS1 cipher=AES128-SHA bits=128/128); Sat, 29 Apr 2017 05:20:39 -0700 (PDT) X-Google-Original-From: Philipp Stephani X-Mailer: git-send-email 2.12.2 In-Reply-To: <83fugvpw24.fsf@gnu.org> X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c0c::243 X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:214404 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. (files-tests--with-advice, files-tests--with-temp-file): New helper macros. --- lisp/files.el | 9 ++++++- test/lisp/files-tests.el | 64 +++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 71 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..4583b1af3c 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,66 @@ files-test-bug-18141-file (start-file-process "foo" nil "true")))) (should (eq (let ((default-directory "/:/")) (shell-command "true")) 0))) +(defmacro files-tests--with-advice (symbol where function &rest body) + (declare (indent 3)) + (cl-check-type symbol symbol) + (cl-check-type where keyword) + (cl-check-type function function) + (macroexp-let2 nil function function + `(progn + (advice-add #',symbol ,where ,function) + (unwind-protect + (progn ,@body) + (advice-remove #',symbol ,function))))) + +(defmacro files-tests--with-temp-file (name &rest body) + (declare (indent 1)) + (cl-check-type name symbol) + `(let ((,name (make-temp-file "emacs"))) + (unwind-protect + (progn ,@body) + (delete-file ,name)))) + +(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." + (files-tests--with-temp-file temp-file-name + (with-temp-buffer + (let* ((buffer-visiting-file (current-buffer)) + (actual-args ()) + (log (lambda (&rest args) (push args actual-args)))) + (insert-file-contents (concat "/:" temp-file-name) :visit) + (should (stringp buffer-file-name)) + (should (string-prefix-p "/:" buffer-file-name)) + (should (consp (visited-file-modtime))) + (should (equal (find-file-name-handler buffer-file-name + #'verify-visited-file-modtime) + #'file-name-non-special)) + (files-tests--with-advice file-name-non-special :before log + ;; This should call the file name handler with the right + ;; buffer and not signal an error. The file hasn't been + ;; modified, so `verify-visited-file-modtime' should return + ;; t. + (should (equal (verify-visited-file-modtime) t)) + (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 hasn't been + ;; modified, so `verify-visited-file-modtime' should return + ;; t. + (should (equal (verify-visited-file-modtime buffer-visiting-file) + t)))) + ;; 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