Subject: Re: bug#79080: 31.0.50; report-emacs-bug-check-org errors with args-out-range

From: Antero Mejr <[email-masked]>
Date: Sat, 26 Jul 2025 15:23:16 +0000

Eli Zaretskii <[email-masked]> writes:

>> Date: Wed, 23 Jul 2025 11:59:48 +0200
>> From:  Daniel Mendler via "Bug reports for GNU Emacs,
>>  the Swiss army knife of text editors" <[email-masked]>
>> 
>> While sending my last bug report I observed the following issue, where
>> `report-emacs-bug-check-org' throws an `args-out-of-range' error. I've
>> got the following stack trace:
>> 
> Antero, I think the bug here is in the assumption that the user edits
> the original text inserted by report-emacs-bug only to _add_ text.
> But that might not be true: users could remove some of the original
> text as well.  So something like the below is in order.  But I also
> wonder why we should look for the regular expression only in part of
> the message to be sent.  Can you explain why you did that?

The Features: section of the original text contains the string " org ",
which will match the regex and always flag a false positive.

The snippet you posted works but I think it will match that " org "
feature if the user removes any of the original text.

I attached a patch that compares the number of matches in the original
text to the edited text. This should avoid false positives unless the
user deletes the " org " strings from the original text. And it will fix
the error.

>From c92b9e63f30bde4b6ec0e94ca4ece8494c21c8b6 Mon Sep 17 00:00:00 2001
From: Antero Mejr <[email-masked]>
Date: Sat, 26 Jul 2025 15:13:15 +0000
Subject: [PATCH] Fix index error when checking edited bug reports

* lisp/mail/emacsbug.el (report-emacs-bug-check-org): Improve regex
check.  (Bug#79080)
---
 lisp/mail/emacsbug.el | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/lisp/mail/emacsbug.el b/lisp/mail/emacsbug.el
index 5ffb86e68b6..d43647a12ca 100644
--- a/lisp/mail/emacsbug.el
+++ b/lisp/mail/emacsbug.el
@@ -427,13 +427,16 @@ emacs-build-description
 (defun report-emacs-bug-check-org ()
   "Warn the user if the bug report mentions org-mode."
   (unless report-emacs-bug-no-confirmation
-    (goto-char (point-max))
-    (skip-chars-backward " \t\n")
-    (let* ((text (buffer-substring-no-properties (point-min) (point)))
-           (l (length report-emacs-bug-orig-text))
-           (text (substring text 0 l))
-           (org-regex "\\b[Oo]rg\\(-mode\\)?\\b"))
-      (when (string-match-p org-regex text)
+    (let* ((org-regex "\\(^\\|\\s-\\)[Oo]rg\\(-mode\\)?\\(\\s-\\|$\\)")
+           (count (lambda (r s)
+                    (let ((c 0) (start 0))
+                      (while (string-match r s start)
+                        (setq c (1+ c))
+                        (setq start (match-end 0)))
+                      c)))
+           (m (funcall count org-regex (buffer-string)))
+           (m-orig (funcall count org-regex report-emacs-bug-orig-text)))
+      (when (> m m-orig)
         (when (yes-or-no-p "Is this bug about org-mode?")
           (error (substitute-command-keys "\
 Not sending, use \\[org-submit-bug-report] to report an Org-mode bug.")))))))
-- 
2.34.1