GNU bug report logs - #79057
30.1; `split-string` unexpectedly clears match data when called on an unrelated string.

Previous Next

Package: emacs;

Reported by: Jennifer and Navid Madani <jnmadani <at> hotmail.com>

Date: Sun, 20 Jul 2025 10:51:02 UTC

Severity: normal

Tags: notabug

Found in version 30.1

Done: Eli Zaretskii <eliz <at> gnu.org>

Full log


View this message in rfc822 format

From: Manuel Giraud <manuel <at> ledu-giraud.fr>
To: Jennifer and Navid Madani <jnmadani <at> hotmail.com>
Cc: 79057 <at> debbugs.gnu.org
Subject: bug#79057: 30.1; `split-string` unexpectedly clears match data when called on an unrelated string.
Date: Sun, 20 Jul 2025 14:22:43 +0200
Jennifer and Navid Madani <jnmadani <at> hotmail.com> writes:

> Run test1 in the code snippet below for reproducing the bug.
>
> I tested it using emacs -Q on macOS and Ubuntu with the same result.
>
>
> (setq *MULTI-LAB-ENTRY-RE* "^\\([[:alpha:]]\\)?[[:space:]]?\\([[:digit:]]\\{2\\}/[[:digit:]]\\{2\\}/[[:digit:]]\\{4\\}\\)[[:space:]]+\\([[:digit:]]\\{2\\}:[[:digit:]]\\{2\\}\\)[[:space:]]+\\(.+\\)")
>
>
> (defun test1 ()
>   (let ((line "a 05/22/2025 14:32 BLOOD WBC 10.4 H K/uL 4.5 - 10.0"))
>     (string-match *MULTI-LAB-ENTRY-RE* line)
>     (message "match-data after string-match: %S" (match-data))
>     (split-string "dummy string") ;; Do NOT pass 'line' here
>     (message "match-data after split-string: %S" (match-data))
>     (message "group 1: %S" (match-string 1))))
>
> (test1)

Hi,

I think it is expected behaviour.  Both `string-match' and
`split-string' modify the *global* match data.  Maybe you'd have to use
`save-match-data' to prevent this.
-- 
Manuel Giraud




This bug report was last modified 25 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.