From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Ioannis Kappas Newsgroups: gmane.emacs.bugs Subject: bug#53808: 29.0.50; ansi colorization process could block indefinetly on stray ESC char Date: Mon, 7 Feb 2022 07:51:44 +0000 Message-ID: References: <87fsoxasfs.fsf@gnus.org> <87ee4fwx3o.fsf@miha-pc> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="29930"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Lars Ingebrigtsen , 53808@debbugs.gnu.org To: Miha =?UTF-8?Q?Rihtar=C5=A1i=C4=8D?= Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Feb 07 09:02:37 2022 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1nGyyr-0007du-9x for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 07 Feb 2022 09:02:37 +0100 Original-Received: from localhost ([::1]:44924 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nGyyo-00086A-Js for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 07 Feb 2022 03:02:34 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:49836) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nGypa-0004t9-R4 for bug-gnu-emacs@gnu.org; Mon, 07 Feb 2022 02:53:04 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:46890) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nGypa-0001jQ-26 for bug-gnu-emacs@gnu.org; Mon, 07 Feb 2022 02:53:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nGypZ-0004qg-O7 for bug-gnu-emacs@gnu.org; Mon, 07 Feb 2022 02:53:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Ioannis Kappas Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 07 Feb 2022 07:53:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 53808 X-GNU-PR-Package: emacs Original-Received: via spool by 53808-submit@debbugs.gnu.org id=B53808.164422032418566 (code B ref 53808); Mon, 07 Feb 2022 07:53:01 +0000 Original-Received: (at 53808) by debbugs.gnu.org; 7 Feb 2022 07:52:04 +0000 Original-Received: from localhost ([127.0.0.1]:40786 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nGyoe-0004pN-20 for submit@debbugs.gnu.org; Mon, 07 Feb 2022 02:52:04 -0500 Original-Received: from mail-ot1-f42.google.com ([209.85.210.42]:41838) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nGyoZ-0004or-If for 53808@debbugs.gnu.org; Mon, 07 Feb 2022 02:52:03 -0500 Original-Received: by mail-ot1-f42.google.com with SMTP id b12-20020a9d754c000000b0059eb935359eso10330537otl.8 for <53808@debbugs.gnu.org>; Sun, 06 Feb 2022 23:51:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=GN94oPUyCyet+Gmuhq/vO/SnXrH2q6sihwRjUxwAkHo=; b=HBfTijY9CaghyN9dGUcLEEZ4mv0bDI5BIeB1HzPNuGkOquL56Vwy8wxz+ZKOcCaCwr 9gj7tdvwV571RegwFdeHx4UcbFzllQFLGyE2s8d7oZjlGhqkI7dhX2BA5nKLdrZ5ENz7 4+JOdyDm7qC9JmlUPs/oYtcUF2dVBnsKBAZr3wGRHNYV4O2quAA/YN864Aj9qj9bJKlo GVnWTqTx6JV/g33H2gMl/flrTUZQMbXFyAaUjKx/o3vs8YMZo9o0aGRdVhR62l1KbCQj l6pqu1I3r4la/H0Gzs8zoqsE059f8ItGdm3RjuenH2/iqyoJSpIHQ+337YEPUPd1i4kC uUBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=GN94oPUyCyet+Gmuhq/vO/SnXrH2q6sihwRjUxwAkHo=; b=i6cAjbuYAHQid01wbQJAm+2KhrHhVaSqmPY6CMRm8/kgkcGq4RiQs+bn1+n+5CkxIx dJ7AKyFbF1nEoioUYw01tSCUwZ7UuFSPN2WMNd51FUdNtLjJ7aUjgEHuThKwWJtX0euw /DNl+QO7wJI7jDm5c+Yo//hjdG7ARXgu5UpQriewMCebN60I0C9QUIPvYwt8maZmG3Mv SVUVE3pyEUsBo4mqTLoMSffBU8MhUZj/C+BtxaehLqtzMH2zs4NFbIYZtop54zBfTGID lf6MThFHdJmZUXZ//Ecy9ZfwRlmiyUdap3Q7FO9mcYhTPdP4thBQuy5nB1OZhYh/ff4t s0AQ== X-Gm-Message-State: AOAM532Ti7KsTi4t4FOhOpi/xbD4MzjSjLmJWsuOYrg43QvbABOhhiXI OzVrMAkc2MoEq5tcZ7thhq6g9WZBF2d44rlPf0ND5bQXfEU= X-Google-Smtp-Source: ABdhPJzCGvis0z7KimH0wgjJMt3eZ8PVkBPSerjubAf3RXf0YamFKYJV/6AEeTBGHxIykT9vfZop1Q+Yh6SRpIOfLpE= X-Received: by 2002:a05:6830:25c6:: with SMTP id d6mr3755668otu.91.1644220313810; Sun, 06 Feb 2022 23:51:53 -0800 (PST) In-Reply-To: <87ee4fwx3o.fsf@miha-pc> X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:226228 Archived-At: Hi Miha, On Sun, Feb 6, 2022 at 8:30 PM wrote: > Thanks. I took the liberty of working on your patch, adding support for > ansi-color-apply-on-region, ansi-color-filter-region, > ansi-color-filter-apply. I also added some tests as you suggested and > made a minor simplification. > thanks for looking into this! The patch looks good and reduces the issue considerably, but I've noticed there is still some undesired behaviour with non SGR CSI sequences. I was expecting the following test to display the non SGR `\e[a' characters verbatim in the output (this is in the context of the test/lisp/ansi-color-tests.el:ansi-color-incomplete-sequences-test()), (dolist (fun (list ansi-filt ansi-app)) (with-temp-buffer (should (equal (funcall fun "\e[a") "")) (should (equal (funcall fun "\e[33m Z \e[0m") (with-temp-buffer (concat "\e[a" (funcall fun "\e[33m Z \e[0m"))))) )) but fails to do so with Test ansi-color-incomplete-sequences-test condition: (ert-test-failed ((should (equal (funcall fun "\33[33m Z \33[0m") (with-temp-buffer ...))) :form (equal " Z " "\33[a Z ") :value nil :explanation (arrays-of-different-length 3 6 " Z " "\33[a Z " first-mismatch-at 0))) i.e. the "\e[a" seq does not appear in the output. Even before that, I was expecting (equal (funcall fun "\e[a") "") to fail and (equal (funcall fun "\e[a") "\e[a") to be true instead (as this can't be the start of a valid SGR expression). Is there a reason why the ansi-color library tries to match input against the CSI superset sequence instead of the SGR subset? The package appears to be dealing exclusively with the latter and using CSI regexps seems like an unnecessary complication to me. (Just for reference, I'm using the terminology found in the ANSI escape code in wikipedia at https://en.wikipedia.org/w/index.php?title=ANSI_escape_code&oldid=1070369816#Description) The SGR set as I understand it is the char sequence starting with the ESC control character followed by the [ character followed by zero or more of [0-9]+; followed by [0-9]+ followed by m. For example, ESC[33m or ESC[3;31m. This is what I tried to capture as a fragment with the "\e\\(?:\\[\\|$\\)\\(?:(?:[0-9]+;?\\)*" regexp in my original patch. Another minor observation, perhaps the following concat could be moved into defconst in the interest of performance (it appears twice in the patch)? (let ((fragment "")) (push (substring string start - (if (string-match "\033" string start) + (if (string-match + (concat "\\(?:" ansi-color--control-seq-fragment-regexp "\\)\\'") + string start) Best Regards