GNU bug report logs -
#53808
29.0.50; ansi colorization process could block indefinetly on stray ESC char
Previous Next
Reported by: Ioannis Kappas <ioannis.kappas <at> gmail.com>
Date: Sat, 5 Feb 2022 20:53:02 UTC
Severity: normal
Found in version 29.0.50
Fixed in version 29.1
Done: Lars Ingebrigtsen <larsi <at> gnus.org>
Bug is archived. No further changes may be made.
Full log
Message #11 received at 53808 <at> debbugs.gnu.org (full text, mbox):
(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))
)
This bug report was last modified 3 years and 106 days ago.
Previous Next
GNU bug tracking system
Copyright (C) 1999 Darren O. Benham,
1997,2003 nCipher Corporation Ltd,
1994-97 Ian Jackson.