emacs-diffs
[Top][All Lists]
Advanced

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

master 8a253a9: Fix replace-in-string infloop with empty pattern string


From: Mattias Engdegård
Subject: master 8a253a9: Fix replace-in-string infloop with empty pattern string (bug#43598)
Date: Fri, 25 Sep 2020 07:18:59 -0400 (EDT)

branch: master
commit 8a253a96a0db4dd585ab787345657d952c7babec
Author: Mattias Engdegård <mattiase@acm.org>
Commit: Mattias Engdegård <mattiase@acm.org>

    Fix replace-in-string infloop with empty pattern string (bug#43598)
    
    * lisp/subr.el (replace-in-string): Raise an error if FROMSTRING is
    empty.
    * test/lisp/subr-tests.el (replace-in-string): Add test case.
---
 lisp/subr.el            | 2 ++
 test/lisp/subr-tests.el | 4 +++-
 2 files changed, 5 insertions(+), 1 deletion(-)

diff --git a/lisp/subr.el b/lisp/subr.el
index 33ed0bc..fba31b7 100644
--- a/lisp/subr.el
+++ b/lisp/subr.el
@@ -4432,6 +4432,8 @@ Unless optional argument INPLACE is non-nil, return a new 
string."
 (defun replace-in-string (fromstring tostring instring)
   "Replace FROMSTRING with TOSTRING in INSTRING each time it occurs."
   (declare (pure t))
+  (when (equal fromstring "")
+    (signal 'wrong-length-argument fromstring))
   (let ((start 0)
         (result nil)
         pos)
diff --git a/test/lisp/subr-tests.el b/test/lisp/subr-tests.el
index fa728e4..505408f 100644
--- a/test/lisp/subr-tests.el
+++ b/test/lisp/subr-tests.el
@@ -464,7 +464,9 @@ See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=19350.";
   (should (equal (replace-in-string "\377" "x" "a\377b")
                  "axb"))
   (should (equal (replace-in-string "\377" "x" "a\377ø")
-                 "axø")))
+                 "axø"))
+
+  (should-error (replace-in-string "" "x" "abc")))
 
 (provide 'subr-tests)
 ;;; subr-tests.el ends here



reply via email to

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