unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
* bug#44861: 27.1; [PATCH] signal in `replace-regexp-in-string'
@ 2020-11-25  4:02 Shigeru Fukaya
  2020-11-25 10:58 ` Mattias Engdegård
  0 siblings, 1 reply; 13+ messages in thread
From: Shigeru Fukaya @ 2020-11-25  4:02 UTC (permalink / raw)
  To: 44861

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


`replace-regexp-in-string' sometimes signals an error when REGEXP
contains some bondary sequence.  Difference of searches between
against an original passed string and against an extracted substring
causes the incident.


(replace-regexp-in-string-simple "a\\B" "A" "a aaaa")
	error --> cons: Args out of range: 2, 3
    expected
	==> "a AAAa"

(replace-regexp-in-string "\\Ba" "A" "a aaaa")
	error --> cons: Args out of range: 3, 4
    expected
	==> "a aAAA"

--
Shigeru

[-- Attachment #2: subr.diff --]
[-- Type: application/octet-stream, Size: 937 bytes --]

diff -u /usr/local/share/emacs/27.1/lisp/subr.el /usr/local/share/emacs/27.1/fix/subr-replaceRegexpInString.el
--- /usr/local/share/emacs/27.1/lisp/subr.el	2020-07-30 06:40:41.000000000 +0900
+++ /usr/local/share/emacs/27.1/fix/subr-replaceRegexpInString.el	2020-11-25 12:25:53.954515500 +0900
@@ -4426,9 +4426,9 @@
 	;; Generate a replacement for the matched substring.
 	;; Operate on only the substring to minimize string consing.
 	;; Set up match data for the substring for replacement;
-	;; presumably this is likely to be faster than munging the
-	;; match data directly in Lisp.
-	(string-match regexp (setq str (substring string mb me)))
+	;; reset match-data for substring by subtracting offsets.
+	(set-match-data (mapcar (lambda (n) (and n (- n mb))) (match-data)))
+	(setq str (substring string mb me))
 	(setq matches
 	      (cons (replace-match (if (stringp rep)
 				       rep

Diff finished.  Wed Nov 25 12:29:28 2020

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2020-11-29 13:28 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-11-25  4:02 bug#44861: 27.1; [PATCH] signal in `replace-regexp-in-string' Shigeru Fukaya
2020-11-25 10:58 ` Mattias Engdegård
2020-11-25 14:58   ` Mattias Engdegård
2020-11-25 21:39     ` Stefan Kangas
2020-11-26 12:57       ` Mattias Engdegård
2020-11-26 13:12         ` Lars Ingebrigtsen
2020-11-26 13:39           ` Mattias Engdegård
2020-11-26 14:03             ` Lars Ingebrigtsen
2020-11-26 14:54               ` Mattias Engdegård
2020-11-29 13:28               ` Basil L. Contovounesios
2020-11-26 13:43           ` Stefan Kangas
2020-11-26 14:03             ` Lars Ingebrigtsen
2020-11-26 14:41             ` Eli Zaretskii

Code repositories for project(s) associated with this public inbox

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).