From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Noam Postavsky Newsgroups: gmane.emacs.bugs Subject: bug#32201: 27.0.50; setenv should not change match-data Date: Wed, 18 Jul 2018 18:52:18 -0400 Message-ID: <87601c88d9.fsf@gmail.com> References: <87h8kwe4ja.fsf@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: blaine.gmane.org 1531954273 31229 195.159.176.226 (18 Jul 2018 22:51:13 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 18 Jul 2018 22:51:13 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) Cc: 32201@debbugs.gnu.org To: John Shahid Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Thu Jul 19 00:51:08 2018 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 1ffvHn-00080F-9p for geb-bug-gnu-emacs@m.gmane.org; Thu, 19 Jul 2018 00:51:07 +0200 Original-Received: from localhost ([::1]:38561 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ffvJu-0002FH-4Y for geb-bug-gnu-emacs@m.gmane.org; Wed, 18 Jul 2018 18:53:18 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57100) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ffvJh-0002E3-WE for bug-gnu-emacs@gnu.org; Wed, 18 Jul 2018 18:53:07 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ffvJe-0007ki-Pu for bug-gnu-emacs@gnu.org; Wed, 18 Jul 2018 18:53:06 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:42253) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1ffvJe-0007kO-HU for bug-gnu-emacs@gnu.org; Wed, 18 Jul 2018 18:53:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1ffvJe-0001UI-56 for bug-gnu-emacs@gnu.org; Wed, 18 Jul 2018 18:53:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Noam Postavsky Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Wed, 18 Jul 2018 22:53:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 32201 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 32201-submit@debbugs.gnu.org id=B32201.15319543485679 (code B ref 32201); Wed, 18 Jul 2018 22:53:02 +0000 Original-Received: (at 32201) by debbugs.gnu.org; 18 Jul 2018 22:52:28 +0000 Original-Received: from localhost ([127.0.0.1]:47271 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ffvJ6-0001TR-2f for submit@debbugs.gnu.org; Wed, 18 Jul 2018 18:52:28 -0400 Original-Received: from mail-io0-f169.google.com ([209.85.223.169]:42079) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ffvJ3-0001T7-QK; Wed, 18 Jul 2018 18:52:26 -0400 Original-Received: by mail-io0-f169.google.com with SMTP id g11-v6so5489814ioq.9; Wed, 18 Jul 2018 15:52:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=qL9FOcmRPSY6BJgE5pE5xvif1iHzlxJFtg4f/I13qyk=; b=lknM9wYKJvNsJdwKra7JBxuao/udaPQpScAg6imve4QV2jjZkwjdnvrMKlZRlvDrtM kWHLo0rISUrC95nVlZcmWnlSsM6DJB1pv1yfMMVmo0YN5VFfDzPtTjTKLNUkgX+vA9rw 0SvEODOM5cS1tUX6Sj1pJF5b40KKLcbMerSA54RwyEqt2ssNJmk6prm4zwdwYV6Rc6zg RgVZk6Lw8R/hdm3EPa92c72Gznv6XIslz5WH3iH57lqf0URtEmvgwSZqoI7hp2dioCnn 03mlASvTFSTv7rUc0QueZhG7mpFvQ3b8zPveJUFZ1TZBf2iC2YV0RtjKlFbxZLrAxE4u ZadQ== 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:references:date:in-reply-to :message-id:user-agent:mime-version; bh=qL9FOcmRPSY6BJgE5pE5xvif1iHzlxJFtg4f/I13qyk=; b=bvB0l8vR9gRi2jL2DftWfJI2/PPXxZ15e99boyopRs4337G1Vh3ZhnAqhdw5RehHAU CcIY8z2gtjMyksbZRaqmnyCNsb30KGa/PPLDin+MhQp/00hEU3ujtPVGW50w2oFSrMBl 6gUgPmr2Xvit/l93ZhZa4wQCnxjq4WN/5jkB62aKRsb6U6nQqv3sOUzbrM8IiLes2Lp0 0319PsDXHmCrMU2m7GUTTnJD7H7TgzPYRXhDMWbSTZZEdVqltNrmMximLrrhAlfQhZWj zilxaRzJhRNy6vrlyZZ+NL/9LKHi6pnosPRLMioctiE1vJg8CrKNGovJj7yvQfiRN55/ Orag== X-Gm-Message-State: AOUpUlENoF0hmNm0aWxMRJVczMU0nYy2XxLp/v5rlPuCJLR5pYMV/UM7 vy87UFLxsnWIwMQ8f9//MOMPng== X-Google-Smtp-Source: AAOMgpcHH5BLCqE6aItO7FtTMmYlk6JhS1a5u9j4yia0hHtqZDq3POG87qa7t7s7bE5BsNYrjV8MBw== X-Received: by 2002:a6b:3a55:: with SMTP id h82-v6mr2763316ioa.76.1531954339992; Wed, 18 Jul 2018 15:52:19 -0700 (PDT) Original-Received: from zebian (cbl-45-2-119-34.yyz.frontiernetworks.ca. [45.2.119.34]) by smtp.googlemail.com with ESMTPSA id u125-v6sm210869ita.4.2018.07.18.15.52.18 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Wed, 18 Jul 2018 15:52:19 -0700 (PDT) In-Reply-To: <87h8kwe4ja.fsf@gmail.com> (John Shahid's message of "Wed, 18 Jul 2018 19:18:33 +0000") 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:148647 Archived-At: --=-=-= Content-Type: text/plain tags 32201 + patch quit John Shahid writes: > > (add-hook 'buffer-list-update-hook > (lambda () > (setenv "GOPATH" gopath)))))) > The problem seems to happen when all of the suddent 'find-file' will > start openning weird files. For example, if I'm currently viewing > "~/foo/bar.txt" and use 'C-x C-f' the default file name will be > "~/foo/~jvshahid/foo/bar.txt". After some debugging it turns out that > the following will happen which cause the match-data to be corrupted: > > 1. find-file calls abbreviate-file-name > 2. abbreviate-file-name calls (expand-file-name "~") > 3. expand-file-name runs the buffer-list-update-hook (unknown why) > 4. the hook will use setenv which messes up the match-data > 5. abbreviate-file-name resumes and use the incorrect match-data and return an invalid path > > I don't know why '3' is happening. buffer-list-update-hook gets called by get-buffer-create and kill-buffer; it seems plausible that some file name handlers would use make-temp-buffer which calls both of those. Anyway, I don't think setenv should be changed, rather abbreviate-file-name should save-match-data around the expand-file-name call. After all, today you happened to use setenv in a hook, tomorrow someone will use another match-data modifying function. Here's the patch (intended for emacs-26): --=-=-= Content-Type: text/x-diff Content-Disposition: inline; filename=v1-0001-Add-save-match-data-to-abbreviate-file-name-Bug-3.patch Content-Description: patch >From a0eec7f2e672804f3a7a30e55c821ba2dac213b7 Mon Sep 17 00:00:00 2001 From: Noam Postavsky Date: Wed, 18 Jul 2018 18:45:47 -0400 Subject: [PATCH v1] Add save-match-data to abbreviate-file-name (Bug#32201) * lisp/files.el (abbreviate-file-name): Save match-data around expand-file-name; it is not guaranteed to preserve match-data, and may well do so depending on what file handlers and hooks are in effect. --- lisp/files.el | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lisp/files.el b/lisp/files.el index fb8c34bcae..4eb1560a20 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -1929,7 +1929,7 @@ abbreviate-file-name (save-match-data (string-match "^[a-zA-`]:/$" filename)))) (equal (get 'abbreviated-home-dir 'home) - (expand-file-name "~"))) + (save-match-data (expand-file-name "~")))) (setq filename (concat "~" (match-string 1 filename) -- 2.11.0 --=-=-=--