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: Sun, 23 Apr 2017 19:06:07 +0200 Message-ID: <20170423170607.10650-1-phst@google.com> References: NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1492967219 22339 195.159.176.226 (23 Apr 2017 17:06:59 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 23 Apr 2017 17:06:59 +0000 (UTC) Cc: Philipp Stephani To: emacs-devel@gnu.org Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Sun Apr 23 19:06:55 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 1d2KyN-0005iK-1y for ged-emacs-devel@m.gmane.org; Sun, 23 Apr 2017 19:06:55 +0200 Original-Received: from localhost ([::1]:39969 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d2KyS-0006wj-Nw for ged-emacs-devel@m.gmane.org; Sun, 23 Apr 2017 13:07:00 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:60610) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1d2Kxp-0006wa-9u for emacs-devel@gnu.org; Sun, 23 Apr 2017 13:06:22 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1d2Kxl-00007H-AK for emacs-devel@gnu.org; Sun, 23 Apr 2017 13:06:21 -0400 Original-Received: from mail-wm0-x236.google.com ([2a00:1450:400c:c09::236]:36523) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1d2Kxl-00006x-2A for emacs-devel@gnu.org; Sun, 23 Apr 2017 13:06:17 -0400 Original-Received: by mail-wm0-x236.google.com with SMTP id u65so7469040wmu.1 for ; Sun, 23 Apr 2017 10:06:16 -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=eDxvUHdJKzWYihc/l9yMRdsTISygBoJ5O4rO2aU3x1qvoF6WEaofTMlp4UUUnfhrgA VZK/OT8xGVJ7D5xGgojpSRPW6cJnScQ/SGnFNSeMeieO7sTHxv9ehjOILATBjuCDzFZh uxROjQuPilKP0MPhXVjzAT6F5P5a8IgDtnayXKIM/AAgUIHEelEbsiTqxRMb4En+7IgO 4xaHKdDbhuF/7zatGqvaYyWLkdJDAtbyl/xmD3aBs1UqZUaWOdyGF13q3cw/C69zSZlg OVEM0XAx5PgBbPN26jRzJcrdoHtO/8upjm/qQAc/c35LJN/q/uQC5YQSvrr1Hf1N/gmF GLtg== 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=fbPsc7k0wGedom+CtWuwuZxuHHV8UUmoMeXDOtlAJOxgu4mez01wFrQXwqI0bjOiRt 2ECUvL2ySDt7J1ddWBngIrFJSPWYoQGu/TY/2r5PK9nCKVj+25TMm5G9jg14ihIvhQAy AHkQjmUo1uvmfeaXZ4EL18l4znYruyap88ryz+M7pmSCj9wER+WCApIfh01uzrxFYPGf D34XrZtBQSDDqxudpjw+EQkvIFxBoxUIwS6gJr4V+gx3pjYNENFwlmNhJy8tvM8viF0R UdhviwLY8VRzkm6hi2hE++ecnymRnkOTmCuwvif3NVHKKA9Bp3Lm8iiL5gcsBghC62MW bAKQ== X-Gm-Message-State: AN3rC/7zQhTe51021SJ2bLuh+WBfsMqefBrM/NZ+KLrwEtc31VcgAigK HulyDxJ41NZkS6wniOq0WQ== X-Received: by 10.28.58.21 with SMTP id h21mr6697636wma.9.1492967175754; Sun, 23 Apr 2017 10:06:15 -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 l5sm6541325wma.6.2017.04.23.10.06.14 (version=TLS1 cipher=AES128-SHA bits=128/128); Sun, 23 Apr 2017 10:06:14 -0700 (PDT) X-Google-Original-From: Philipp Stephani X-Mailer: git-send-email 2.12.2 In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:400c:c09::236 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:214249 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