From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: miha--- via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#53808: 29.0.50; ansi colorization process could block indefinetly on stray ESC char Date: Mon, 07 Feb 2022 12:42:20 +0100 Message-ID: <86r18eucmb.fsf@miha-pc> References: <87fsoxasfs.fsf@gnus.org> <87ee4fwx3o.fsf@miha-pc> Reply-To: Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="15441"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Lars Ingebrigtsen , 53808@debbugs.gnu.org To: Ioannis Kappas Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Mon Feb 07 12:33:14 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 1nH2Gf-0003nK-Jf for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 07 Feb 2022 12:33:14 +0100 Original-Received: from localhost ([::1]:54656 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nH2Ge-0008BM-9w for geb-bug-gnu-emacs@m.gmane-mx.org; Mon, 07 Feb 2022 06:33:12 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:47742) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nH2GU-00087e-K9 for bug-gnu-emacs@gnu.org; Mon, 07 Feb 2022 06:33:02 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:47264) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nH2GT-0001jk-LP for bug-gnu-emacs@gnu.org; Mon, 07 Feb 2022 06:33:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nH2GT-0000hk-Ju for bug-gnu-emacs@gnu.org; Mon, 07 Feb 2022 06:33:01 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 07 Feb 2022 11:33: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.16442335662685 (code B ref 53808); Mon, 07 Feb 2022 11:33:01 +0000 Original-Received: (at 53808) by debbugs.gnu.org; 7 Feb 2022 11:32:46 +0000 Original-Received: from localhost ([127.0.0.1]:41161 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nH2GE-0000hF-7Q for submit@debbugs.gnu.org; Mon, 07 Feb 2022 06:32:46 -0500 Original-Received: from kamnitnik.top ([209.250.245.214]:33982) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nH2G9-0000gz-GY for 53808@debbugs.gnu.org; Mon, 07 Feb 2022 06:32:44 -0500 Original-Received: from localhost (unknown [IPv6:2a00:ee2:e04:9300:b7eb:7ae7:cc56:e0da]) by kamnitnik.top (Postfix) with ESMTPSA id 3BD9B9C70E; Mon, 7 Feb 2022 11:32:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kamnitnik.top; s=mail; t=1644233560; bh=g09K5kHDD4M/eFr9Bf+7qz/KfCMKHoSHlQmrB5AU5jU=; h=From:To:Cc:Subject:In-Reply-To:References:Date:From; b=IuCOnPVQnYarkr3vZnIHZcGAv7zSX+jdid1w7iGQFjn+H9JYokxiFHVdOSMOBOSZn BRAVVtjWF/u8ceefAh+goc2wep782sTELGH8bpo1bpEI4yDhbqUyTPh1B5u+uqR5YX zrIcOZwdFdVbbrB0y7uVOjdYnvXSwB25NunTVJej9zkzYEa5RWK6JC95TXLWFWq+Ec CwpYKC1a1EvT/gl/9kF2IjxYak1ASQC5Er26mI4dCm6h3j2jUJ4x9wx/lpohEvOmyX iaQroB5ShhKV60F/CGRtrbbk4VctxeHbfNp294z0pBvHeUhld5vRnkAvGCOyIXboTW cICNaAkZoMkkw== In-Reply-To: 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:226240 Archived-At: --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Ioannis Kappas writes: > 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. Seems like filtering of non-SGR CSI sequences was introduced in commit from Sat May 29 14:25:00 2010 -0400 (bc8d33d540d079af28ea93a0cf8df829911044ca) to fix bug#6085. And indeed, if I try to set 'ansi-color-control-seq-regexp' to the more specific SGR-only regexp "\e\\[[0-9;]*m", I get a lot of distracting "^[[K" in the output of "grep --color=3Dalways" on my system. > (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=3DANSI_escape_code&oldid=3D107= 0369816#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. I believe 'ansi-color--control-seq-fragment-regexp' should mirror 'ansi-color-control-seq-regexp' as exactly as possible. In other words, if one matches all CSI sequences, the other shouldn't match only SGR sequences. > 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) Thanks, noted, I will hopefully send the simple patch soon. > Best Regards Thanks, best regards. --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQJHBAEBCAAxFiEEmxVnesoT5rQXvVXnswkaGpIVmT8FAmIBBZwTHG1paGFAa2Ft bml0bmlrLnRvcAAKCRCzCRoakhWZP5VqEACSrMTXg/T9ZF2ZSpV6q96PoD1Z0MZQ L7QZoCrdqt8Sfp9eZxjGVZe9gkxwcqK1X8YPR5JCh7tKn5/j7yvfwtKovq2VOdqV kvmkcFb/eKSV1XOzfUnjB9urIqDmiJOF3S7xwfw+3t/UG/+tVK6H5ldv4KE/KnvQ bs67NmarfIB0EV4+wVwe7eNnE+ByS7fgD7b/QYcRUDYjpq8Ga2CsNTICFslxd39c z5zDj8XOtUArdwQpz/dWloobkGePDBPcbX0EyyqzJVwSAJAnrgE95KEW92w2UAhz ueu9vIUPitEv8q3Bl3e8dJbxqL5sxlW8Fe6+/mFf4/tHX2gMvIifdoqZITsWRpgw 9R2mrb7pVEJKO2iuS2F+1oXeKNc3Iiqavl3CSPFWYvz9S17KkC8OwuMldJvottCt gIca9nGyMqZNBW25nF8nF+N0tcmN2rL/5qxn7nXQ1zwib/48lTy3RQZD5BITDPt0 HPDWu9Vb8jKmfMmyu2nZ3k7+SLVSGpO0werhQHkrsF1NTWznRY7LvKO9M6IOMQEf FLCTzT8GA2UcIfD//yG/aaNcSxgvUKk/zqwLourF6RbdvbxVQegxUdkfYHGewJLg hKIW4kBSi1T9gZboxnedY4sn1TdE/cHUbyArcn0ibpLRcvYjfdpbaXAprkG8tMwB oxRjvvL7nIjGrg== =y0Qa -----END PGP SIGNATURE----- --=-=-=--