aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Engdegård2020-05-22 12:21:28 +0200
committerMattias Engdegård2020-05-27 16:29:43 +0200
commitc5cf630ecd467fdcac13928f7e240cfc98cedc7a (patch)
tree874eb44ee930b78552765a2fb56d8ee4d1eea1c5
parent0fc4989f34bdaf1bc443d05ece886ea91e7bc9cc (diff)
downloademacs-c5cf630ecd467fdcac13928f7e240cfc98cedc7a.tar.gz
emacs-c5cf630ecd467fdcac13928f7e240cfc98cedc7a.zip
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.
-rw-r--r--lisp/international/ucs-normalize.el10
-rw-r--r--test/lisp/international/ucs-normalize-tests.el11
2 files changed, 17 insertions, 4 deletions
diff --git a/lisp/international/ucs-normalize.el b/lisp/international/ucs-normalize.el
index 201ff6b9b17..b703d3dd2f2 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."
612(defun ucs-normalize-hfs-nfd-post-read-conversion (len) 612(defun ucs-normalize-hfs-nfd-post-read-conversion (len)
613 (save-excursion 613 (save-excursion
614 (save-restriction 614 (save-restriction
615 (narrow-to-region (point) (+ (point) len)) 615 (save-match-data
616 (ucs-normalize-HFS-NFC-region (point-min) (point-max)) 616 (narrow-to-region (point) (+ (point) len))
617 (- (point-max) (point-min))))) 617 (ucs-normalize-HFS-NFC-region (point-min) (point-max))
618 (- (point-max) (point-min))))))
618 619
619;; Pre-write conversion for `utf-8-hfs'. 620;; Pre-write conversion for `utf-8-hfs'.
620;; _from and _to are legacy arguments (see `define-coding-system'). 621;; _from and _to are legacy arguments (see `define-coding-system').
621(defun ucs-normalize-hfs-nfd-pre-write-conversion (_from _to) 622(defun ucs-normalize-hfs-nfd-pre-write-conversion (_from _to)
622 (ucs-normalize-HFS-NFD-region (point-min) (point-max))) 623 (save-match-data
624 (ucs-normalize-HFS-NFD-region (point-min) (point-max))))
623 625
624;;; coding-system definition 626;;; coding-system definition
625(define-coding-system 'utf-8-hfs 627(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 c36808ad72f..2c60bd318a2 100644
--- a/test/lisp/international/ucs-normalize-tests.el
+++ b/test/lisp/international/ucs-normalize-tests.el
@@ -341,4 +341,15 @@ implementations:
341 (display-buffer (current-buffer))) 341 (display-buffer (current-buffer)))
342 (message "No changes to failing lines needed")))) 342 (message "No changes to failing lines needed"))))
343 343
344(ert-deftest ucs-normalize-save-match-data ()
345 "Verify that match data isn't clobbered (bug#41445)"
346 (string-match (rx (+ digit)) "a47b")
347 (should (equal (match-data t) '(1 3)))
348 (should (equal
349 (decode-coding-string
350 (encode-coding-string "Käsesoßenrührlöffel" 'utf-8-hfs)
351 'utf-8-hfs)
352 "Käsesoßenrührlöffel"))
353 (should (equal (match-data t) '(1 3))))
354
344;;; ucs-normalize-tests.el ends here 355;;; ucs-normalize-tests.el ends here