unofficial mirror of bug-gnu-emacs@gnu.org 
 help / color / mirror / code / Atom feed
From: Ioannis Kappas <ioannis.kappas@gmail.com>
To: 53808@debbugs.gnu.org
Subject: bug#53808: 29.0.50; ansi colorization process could block indefinetly on stray ESC char
Date: Sat, 5 Feb 2022 21:47:50 +0000	[thread overview]
Message-ID: <CAMRHuGCvHwLb5uTndJQAB0YHv6fqZGuyrJQLAqNpnRquQ9GJsA@mail.gmail.com> (raw)
In-Reply-To: <CAMRHuGBLL0Fd1N_vnb+KQHicxp47Ad-ijy=gqmHOfHt8V+c1Uw@mail.gmail.com>

(sorry, I sent out the wrong patch, the correct one is

modified   lisp/ansi-color.el
@@ -501,6 +501,20 @@ ansi-color-filter-apply
       (setcar (cdr context) fragment))
     (apply #'concat (nreverse result))))

+(defconst ansi-color--sgr-partial-regex
+  "\e\\(?:\\[\\|$\\)\\(?:[0-9]+;?\\)*"
+  "A regexp for locating the beginning of a partial SGR
+  sequence.")
+
+(defun ansi-color--sgr-fragment-pos (string start)
+  "Check if STRING ends with a partial SGR sequence and return
+its position or nil otherwise. Start looking in STRING at position START."
+  (save-match-data
+    (when (and (string-match ansi-color--sgr-partial-regex string start)
+               (or (= (match-end 0) 0)
+                   (= (match-end 0) (length string))) )
+      (match-beginning 0))))
+
 (defun ansi-color-apply (string)
   "Translates SGR control sequences into text properties.
 Delete all other control sequences without processing them.
@@ -549,8 +563,8 @@ ansi-color-apply
       (put-text-property start (length string)
                          'font-lock-face face string))
     ;; save context, add the remainder of the string to the result
-    (if (string-match "\033" string start)
-        (let ((pos (match-beginning 0)))
+    (if-let ((pos (ansi-color--sgr-fragment-pos string start)))
+        (progn
           (setcar (cdr context) (substring string pos))
           (push (substring string start pos) result))
       (push (substring string start) result))



)





  reply	other threads:[~2022-02-05 21:47 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-02-05 20:52 bug#53808: 29.0.50; ansi colorization process could block indefinetly on stray ESC char Ioannis Kappas
2022-02-05 21:00 ` Ioannis Kappas
2022-02-05 21:47   ` Ioannis Kappas [this message]
2022-02-05 21:56   ` Lars Ingebrigtsen
2022-02-05 22:05     ` Ioannis Kappas
2022-02-06 20:36       ` miha--- via Bug reports for GNU Emacs, the Swiss army knife of text editors
2022-02-06 22:55         ` Lars Ingebrigtsen
2022-02-07  7:51         ` Ioannis Kappas
2022-02-07 11:42           ` miha--- via Bug reports for GNU Emacs, the Swiss army knife of text editors

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAMRHuGCvHwLb5uTndJQAB0YHv6fqZGuyrJQLAqNpnRquQ9GJsA@mail.gmail.com \
    --to=ioannis.kappas@gmail.com \
    --cc=53808@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).