Subject: bug#40859: Clicking the wrap-prefix string inside a button causes an error

From: Clément Pit-Claudel <[email-masked]>
Date: Sun, 26 Apr 2020 12:44:15 -0400

On 26/04/2020 09.43, Eli Zaretskii wrote:
>> From: Clément Pit-Claudel <[email-masked]>
>> Date: Sat, 25 Apr 2020 23:40:38 -0400
>>
>> The following snippet inserts a button with a long label and a wrap-prefix.  Clicking the prefix causes an error, whose backtrace is shown below.
> 
> Isn't that a cockpit error?

Here's a tentative patch, but I can't claim to understand the button.el code well :/
>From 11034798933a1e0c9498b0409cd463acb822f2d3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Cl=C3=A9ment=20Pit-Claudel?= <[email-masked]>
Date: Sun, 26 Apr 2020 12:41:42 -0400
Subject: [PATCH] Only treat display strings as buttons if they have a 'button
 property

* lisp/button.el (push-button): Use posn-point instead of posn-string
if the string doesn't have a 'button property (Bug#40859).
---
 lisp/button.el | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/lisp/button.el b/lisp/button.el
index b3afc4eca2..c33a3e8ac2 100644
--- a/lisp/button.el
+++ b/lisp/button.el
@@ -469,10 +469,12 @@ push-button
       ;; POS is a mouse event; switch to the proper window/buffer
       (let ((posn (event-start pos)))
 	(with-current-buffer (window-buffer (posn-window posn))
-	  (if (posn-string posn)
-	      ;; mode-line, header-line, or display string event.
-	      (button-activate (posn-string posn) t)
-	    (push-button (posn-point posn) t))))
+          (let* ((str (posn-string posn))
+                 (str-button (get-text-property (cdr str) 'button (car str))))
+	    (if (and str str-button)
+	        ;; mode-line, header-line, or display string event.
+	        (button-activate str t)
+	      (push-button (posn-point posn) t)))))
     ;; POS is just normal position
     (let ((button (button-at (or pos (point)))))
       (when button
-- 
2.17.1