Subject: Re: bug#79057: 30.1; `split-string` unexpectedly clears match data when called on an unrelated string.

From: Eli Zaretskii <[email-masked]>
Date: Sun, 20 Jul 2025 15:05:41 +0300

tags 79057 notabug
thanks

> From: Jennifer and Navid Madani <[email-masked]>
> Date: Sun, 20 Jul 2025 00:44:20 +0000
> 
> 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)

It isn't a bug: any Emacs function can modify match-data, unless its
doc string explicitly says it doesn't.  And in this case, the doc
string even takes extra care to say it does:

  Modifies the match data; use ‘save-match-data’ if necessary.

You need to change your code to use save-match-data.