emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

master c5cf630: Don't clobber match data in utf-8-hfs conversion (bug#41


From: Mattias Engdegård
Subject: master c5cf630: Don't clobber match data in utf-8-hfs conversion (bug#41445)
Date: Wed, 27 May 2020 10:30:43 -0400 (EDT)

branch: master
commit c5cf630ecd467fdcac13928f7e240cfc98cedc7a
Author: Mattias Engdegård <address@hidden>
Commit: Mattias Engdegård <address@hidden>

    Don't clobber match data in utf-8-hfs conversion (bug#41445)
    
    Reported by Ture PÃ¥lsson.
    
    * lisp/international/ucs-normalize.el
    (ucs-normalize-hfs-nfd-post-read-conversion)
    (ucs-normalize-hfs-nfd-pre-write-conversion):
    Use save-match-data to avoid match data clobber in normalisation.
    * test/lisp/international/ucs-normalize-tests.el
    (ucs-normalize-save-match-data): New test.
---
 lisp/international/ucs-normalize.el            | 10 ++++++----
 test/lisp/international/ucs-normalize-tests.el | 11 +++++++++++
 2 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/lisp/international/ucs-normalize.el 
b/lisp/international/ucs-normalize.el
index 201ff6b..b703d3d 100644
--- a/lisp/international/ucs-normalize.el
+++ b/lisp/international/ucs-normalize.el
@@ -612,14 +612,16 @@ COMPOSITION-PREDICATE will be used to compose region."
 (defun ucs-normalize-hfs-nfd-post-read-conversion (len)
   (save-excursion
     (save-restriction
-      (narrow-to-region (point) (+ (point) len))
-      (ucs-normalize-HFS-NFC-region (point-min) (point-max))
-      (- (point-max) (point-min)))))
+      (save-match-data
+        (narrow-to-region (point) (+ (point) len))
+        (ucs-normalize-HFS-NFC-region (point-min) (point-max))
+        (- (point-max) (point-min))))))
 
 ;; Pre-write conversion for `utf-8-hfs'.
 ;; _from and _to are legacy arguments (see `define-coding-system').
 (defun ucs-normalize-hfs-nfd-pre-write-conversion (_from _to)
-  (ucs-normalize-HFS-NFD-region (point-min) (point-max)))
+  (save-match-data
+    (ucs-normalize-HFS-NFD-region (point-min) (point-max))))
 
 ;;; coding-system definition
 (define-coding-system 'utf-8-hfs
diff --git a/test/lisp/international/ucs-normalize-tests.el 
b/test/lisp/international/ucs-normalize-tests.el
index c36808a..2c60bd3 100644
--- a/test/lisp/international/ucs-normalize-tests.el
+++ b/test/lisp/international/ucs-normalize-tests.el
@@ -341,4 +341,15 @@ implementations:
           (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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]