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 14:20:27 +0200 Message-ID: <20170429122027.39318-1-phst__17532.0142567672$1493468477$gmane$org@google.com> References: <83fugvpw24.fsf@gnu.org> NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1493468477 18740 195.159.176.226 (29 Apr 2017 12:21:17 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sat, 29 Apr 2017 12:21:17 +0000 (UTC) Cc: Philipp Stephani To: 25951@debbugs.gnu.org, npostavs@users.sourceforge.net, emacs-devel@gnu.org, eliz@gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sat Apr 29 14:21:13 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 1d4RNA-0004n2-5P for geb-bug-gnu-emacs@m.gmane.org; Sat, 29 Apr 2017 14:21:12 +0200 Original-Received: from localhost ([::1]:41035 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d4RNF-0000x3-Om for geb-bug-gnu-emacs@m.gmane.org; Sat, 29 Apr 2017 08:21:17 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:34669) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d4RN3-0000vU-Tf for bug-gnu-emacs@gnu.org; Sat, 29 Apr 2017 08:21:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d4RN0-0005OT-NR for bug-gnu-emacs@gnu.org; Sat, 29 Apr 2017 08:21:05 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:47436) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d4RN0-0005OO-Ji for bug-gnu-emacs@gnu.org; Sat, 29 Apr 2017 08:21:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1d4RN0-0000W3-EX for bug-gnu-emacs@gnu.org; Sat, 29 Apr 2017 08:21: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 12:21: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.14934684471941 (code B ref 25951); Sat, 29 Apr 2017 12:21:02 +0000 Original-Received: (at 25951) by debbugs.gnu.org; 29 Apr 2017 12:20:47 +0000 Original-Received: from localhost ([127.0.0.1]:45635 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d4RMl-0000VE-JN for submit@debbugs.gnu.org; Sat, 29 Apr 2017 08:20:47 -0400 Original-Received: from mail-wr0-f195.google.com ([209.85.128.195]:36735) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1d4RMk-0000V1-BA for 25951@debbugs.gnu.org; Sat, 29 Apr 2017 08:20:46 -0400 Original-Received: by mail-wr0-f195.google.com with SMTP id v42so9532915wrc.3 for <25951@debbugs.gnu.org>; Sat, 29 Apr 2017 05:20:46 -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=cCFJMbVk5QnnSZA6rrYxur3cy0Izmxqg7zAl0/h1ntR/UY//ORJWSw8ATRF02RpXFA 2C54koqORE5si8W/UZFilsToudEHs9tEm+u0oXtsusoAZfAvkN7izfbV+brl1bTf6w87 SUuYPc1DTFfIOkZ4x2CfSw0XWp1x+jvd7XXSiqQ+mU+gujh1wOpCafgO/aa/uhI4akWP xs8eNaTn7A2GXy6Anho55Wh4MDJSqplVmlhxae3eU7mCs8EtAW//0CLcxRbHnFSbdBh+ UhmpQjaIEKoER0SSiYGcE216UDQx9PzDEbdfUShvxOhWMyOCj3SFMaHZHYzAsOEneLU1 0jbg== X-Gm-Message-State: AN3rC/4/H35I904cjGyu2qdoXsoRVBDAD9faRjtREGPT5U6z2wGV7jA8 ofgpk/XZ1jp6/g== 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-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:132103 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