GNU bug report logs - #54218
[PATCH] Magic number regexp shouldn't match beyond end-of-line.

Previous Next

Package: emacs;

Reported by: "Andrew L. Moore" <slewsys <at> gmail.com>

Date: Wed, 2 Mar 2022 04:53:01 UTC

Severity: normal

Tags: patch

Fixed in version 29.1

Done: Lars Ingebrigtsen <larsi <at> gnus.org>

Bug is archived. No further changes may be made.

Full log


View this message in rfc822 format

From: "Andrew L. Moore" <slewsys <at> gmail.com>
To: 54218 <at> debbugs.gnu.org
Cc: "Andrew L. Moore" <slewsys <at> gmail.com>
Subject: bug#54218: [PATCH] Magic number regexp shouldn't match beyond end-of-line.
Date: Tue, 1 Mar 2022 23:52:50 -0500
Repeat magic number search to work around match-data loss
when `save-window-excursion' is called.
---
 lisp/progmodes/executable.el | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/lisp/progmodes/executable.el b/lisp/progmodes/executable.el
index d7c093444e..9116bdea9d 100644
--- a/lisp/progmodes/executable.el
+++ b/lisp/progmodes/executable.el
@@ -232,7 +232,8 @@ executable-set-magic
       (save-excursion
        (goto-char (point-min))
        (add-hook 'after-save-hook 'executable-chmod nil t)
-       (if (looking-at "#![ \t]*\\(.*\\)$")
+        ;; Regexp shouldn't match beyond end-of-line.
+       (if (looking-at "#![ \t]*\\([^\n]*\\)$")
            (and (goto-char (match-beginning 1))
                 ;; If the line ends in a space,
                 ;; don't offer to change it.
@@ -247,8 +248,13 @@ executable-set-magic
                                      "Replace magic number by `#!%s'? "
                                      argument))))
                     (progn
-                      (replace-match argument t t nil 1)
-                      (message "Magic number changed to `#!%s'" 
argument))))
+                       ;; Repeat search to work around match-data loss
+                       ;; from call to `save-window-excursion' above.
+                       (goto-char (point-min))
+                       (if (looking-at "^#![ \t]*\\([^\n]*\\)$")
+                           (progn
+                            (replace-match argument t t nil 1)
+                            (message "Magic number changed to `#!%s'" 
argument))))))
          (insert "#!" argument ?\n)
          (message "Magic number changed to `#!%s'" argument))))
     interpreter)
-- 




This bug report was last modified 3 years and 77 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.