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

From: Manuel Giraud <[email-masked]>
Date: Sun, 20 Jul 2025 14:22:43 +0200

Jennifer and Navid Madani <[email-masked]> 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