all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: "Mattias Engdegård" <mattiase@acm.org>
To: "Ture Pålsson" <ture@turepalsson.se>
Cc: 41445@debbugs.gnu.org
Subject: bug#41445: 26.3; Query-replace triggers "match data clobbered by..."
Date: Fri, 22 May 2020 12:46:03 +0200	[thread overview]
Message-ID: <B49CCB00-5C7B-4E04-A134-AEACDE273928@acm.org> (raw)
In-Reply-To: <m2zha0o8vn.fsf@turepalsson.se>

[-- Attachment #1: Type: text/plain, Size: 110 bytes --]

tags 41445 patch
stop

Thank you! Clearly nobody expects normalisation functions to clobber match data.


[-- Attachment #2: 0001-Don-t-clobber-match-data-in-Unicode-normalisation-bu.patch --]
[-- Type: application/octet-stream, Size: 3695 bytes --]

From 851cbe5507e872d8649d457889c4f87395bd63c2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mattias=20Engdeg=C3=A5rd?= <mattiase@acm.org>
Date: Fri, 22 May 2020 12:21:28 +0200
Subject: [PATCH] Don't clobber match data in Unicode normalisation (bug#41445)
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Suggested by Ture Pålsson.

* lisp/international/ucs-normalize.el (ucs-normalize-region):
Wrap regexp searches in save-match-data.
* test/lisp/international/ucs-normalize-tests.el
(ucs-normalize-save-match-data): New test.
---
 lisp/international/ucs-normalize.el           | 33 ++++++++++---------
 .../lisp/international/ucs-normalize-tests.el | 11 +++++++
 2 files changed, 28 insertions(+), 16 deletions(-)

diff --git a/lisp/international/ucs-normalize.el b/lisp/international/ucs-normalize.el
index 201ff6b9b1..6bc08c247b 100644
--- a/lisp/international/ucs-normalize.el
+++ b/lisp/international/ucs-normalize.el
@@ -511,22 +511,23 @@ ucs-normalize-region
 COMPOSITION-PREDICATE will be used to compose region."
   (save-excursion
     (save-restriction
-      (narrow-to-region from to)
-      (goto-char (point-min))
-      (let (start-pos starter)
-        (while (re-search-forward quick-check-regexp nil t)
-          (setq starter (string-to-char (match-string 0)))
-          (setq start-pos (match-beginning 0))
-          (ucs-normalize-block
-           ;; from
-           (if (or (= start-pos (point-min))
-                   (and (= 0 (ucs-normalize-ccc starter))
-                        (not (memq starter ucs-normalize-combining-chars))))
-               start-pos (1- start-pos))
-           ;; to
-           (if (looking-at ucs-normalize-combining-chars-regexp)
-               (match-end 0) (1+ start-pos))
-           translation-table composition-predicate))))))
+      (save-match-data
+        (narrow-to-region from to)
+        (goto-char (point-min))
+        (let (start-pos starter)
+          (while (re-search-forward quick-check-regexp nil t)
+            (setq starter (string-to-char (match-string 0)))
+            (setq start-pos (match-beginning 0))
+            (ucs-normalize-block
+             ;; from
+             (if (or (= start-pos (point-min))
+                     (and (= 0 (ucs-normalize-ccc starter))
+                          (not (memq starter ucs-normalize-combining-chars))))
+                 start-pos (1- start-pos))
+             ;; to
+             (if (looking-at ucs-normalize-combining-chars-regexp)
+                 (match-end 0) (1+ start-pos))
+             translation-table composition-predicate)))))))
 
 ;; --------------------------------------------------------------------------------
 
diff --git a/test/lisp/international/ucs-normalize-tests.el b/test/lisp/international/ucs-normalize-tests.el
index c36808ad72..2c60bd318a 100644
--- a/test/lisp/international/ucs-normalize-tests.el
+++ b/test/lisp/international/ucs-normalize-tests.el
@@ -341,4 +341,15 @@ ucs-normalize-check-failing-lines
           (display-buffer (current-buffer)))
       (message "No changes to failing lines needed"))))
 
+(ert-deftest ucs-normalize-save-match-data ()
+  "Verify that match data isn't clobbered (bug#41445)"
+  (string-match (rx (+ digit)) "a47b")
+  (should (equal (match-data t) '(1 3)))
+  (should (equal
+           (decode-coding-string
+            (encode-coding-string "Käsesoßenrührlöffel" 'utf-8-hfs)
+            'utf-8-hfs)
+           "Käsesoßenrührlöffel"))
+  (should (equal (match-data t) '(1 3))))
+
 ;;; ucs-normalize-tests.el ends here
-- 
2.21.1 (Apple Git-122.3)


  reply	other threads:[~2020-05-22 10:46 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-22  5:07 bug#41445: 26.3; Query-replace triggers "match data clobbered by..." Ture Pålsson
2020-05-22 10:46 ` Mattias Engdegård [this message]
2020-05-22 11:11   ` Eli Zaretskii
2020-05-22 11:16     ` Mattias Engdegård
2020-05-22 12:07       ` Eli Zaretskii
2020-05-22 12:21         ` Mattias Engdegård
2020-05-22 12:35           ` Eli Zaretskii
2020-05-23 11:36         ` Mattias Engdegård
2020-05-23 12:28           ` Eli Zaretskii
2020-05-23 12:37             ` Philipp Stephani
2020-05-23 13:07               ` Eli Zaretskii
2020-05-23 13:08               ` Mattias Engdegård
2020-05-23 13:36             ` Stefan Monnier
2020-05-23 15:43               ` Drew Adams
2020-05-27 14:31               ` Mattias Engdegård
2020-05-27 15:54                 ` Eli Zaretskii

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=B49CCB00-5C7B-4E04-A134-AEACDE273928@acm.org \
    --to=mattiase@acm.org \
    --cc=41445@debbugs.gnu.org \
    --cc=ture@turepalsson.se \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.