unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Shigeru Fukaya <shigeru.fukaya@gmail.com>
To: 44861@debbugs.gnu.org
Subject: bug#44861: 27.1; [PATCH] signal in `replace-regexp-in-string'
Date: Wed, 25 Nov 2020 13:02:11 +0900	[thread overview]
Message-ID: <4ED6C2DFC045A8C31D0B86@gmail.com> (raw)

[-- 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

             reply	other threads:[~2020-11-25  4:02 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-25  4:02 Shigeru Fukaya [this message]
2020-11-25 10:58 ` bug#44861: 27.1; [PATCH] signal in `replace-regexp-in-string' 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4ED6C2DFC045A8C31D0B86@gmail.com \
    --to=shigeru.fukaya@gmail.com \
    --cc=44861@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).