]> git.eshelyaron.com Git - emacs.git/commitdiff
Fix up previous replace-in-string commit
authorLars Ingebrigtsen <larsi@gnus.org>
Tue, 15 Sep 2020 15:36:36 +0000 (17:36 +0200)
committerLars Ingebrigtsen <larsi@gnus.org>
Tue, 15 Sep 2020 15:36:36 +0000 (17:36 +0200)
* lisp/subr.el (replace-in-string): Fix thinko in implementation.

lisp/subr.el
test/lisp/subr-tests.el

index b8331760e340c1a9415f7cf2c451ec0c47dd17b3..f3c1e206603615ead13c5f9309335df19fc05228 100644 (file)
@@ -4430,7 +4430,11 @@ This function returns a freshly created string."
                             (aref fromstring if)))
               (setq ii (1+ ii)
                     if (1+ if)))
-            (when (= if (length fromstring))
+            (if (not (= if (length fromstring)))
+                ;; We didn't have a match after all.
+                (setq i (1+ i))
+              ;; We had one, so gather the previous part and the
+              ;; substition.
               (when (not (= start i))
                 (push (substring instring start i) result))
               (push tostring result)
index 8bec097aadf3cd6195c125850912ba0077ad269a..2adb4a62e86819a71d6f66929c6701e1d643cc98 100644 (file)
@@ -450,7 +450,13 @@ See https://debbugs.gnu.org/cgi/bugreport.cgi?bug=19350."
   (should (equal (replace-in-string "zot" "bar" "barfoozot")
                  "barfoobar"))
   (should (equal (replace-in-string "z" "bar" "barfoozot")
-                 "barfoobarot")))
+                 "barfoobarot"))
+  (should (equal (replace-in-string "zot" "bar" "zat")
+                 "zat"))
+  (should (equal (replace-in-string "azot" "bar" "zat")
+                 "zat"))
+  (should (equal (replace-in-string "azot" "bar" "azot")
+                 "bar")))
 
 (provide 'subr-tests)
 ;;; subr-tests.el ends here