From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Bob Rogers Newsgroups: gmane.emacs.bugs Subject: bug#53965: 29.0.50; Subject: [PATCH] ietf-drums-remove-whitespace fails on unmatched " and ( Date: Sat, 12 Feb 2022 17:03:47 -0500 Message-ID: Mime-Version: 1.0 Content-Type: text/plain Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="34806"; mail-complaints-to="usenet@ciao.gmane.io" To: 53965@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Feb 12 23:07:11 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 1nJ0Xv-0008ry-GN for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 12 Feb 2022 23:07:11 +0100 Original-Received: from localhost ([::1]:56264 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nJ0Xt-0002z8-US for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 12 Feb 2022 17:07:09 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:55122) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nJ0Ut-00014w-AJ for bug-gnu-emacs@gnu.org; Sat, 12 Feb 2022 17:04:03 -0500 Original-Received: from debbugs.gnu.org ([209.51.188.43]:41953) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nJ0Us-0007Jf-Ly for bug-gnu-emacs@gnu.org; Sat, 12 Feb 2022 17:04:02 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1nJ0Us-0001yc-JQ for bug-gnu-emacs@gnu.org; Sat, 12 Feb 2022 17:04:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Bob Rogers Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 12 Feb 2022 22:04:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 53965 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.16447034387585 (code B ref -1); Sat, 12 Feb 2022 22:04:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 12 Feb 2022 22:03:58 +0000 Original-Received: from localhost ([127.0.0.1]:35850 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nJ0Un-0001yE-UK for submit@debbugs.gnu.org; Sat, 12 Feb 2022 17:03:58 -0500 Original-Received: from lists.gnu.org ([209.51.188.17]:32804) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1nJ0Um-0001y6-7G for submit@debbugs.gnu.org; Sat, 12 Feb 2022 17:03:56 -0500 Original-Received: from eggs.gnu.org ([209.51.188.92]:55104) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nJ0Ul-00013D-SO for bug-gnu-emacs@gnu.org; Sat, 12 Feb 2022 17:03:55 -0500 Original-Received: from [2607:f8b0:4864:20::731] (port=34471 helo=mail-qk1-x731.google.com) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nJ0Ui-0007Hn-3f for bug-gnu-emacs@gnu.org; Sat, 12 Feb 2022 17:03:54 -0500 Original-Received: by mail-qk1-x731.google.com with SMTP id bs32so11326880qkb.1 for ; Sat, 12 Feb 2022 14:03:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rgrjr-com.20210112.gappssmtp.com; s=20210112; h=from:to:subject:date:message-id:mime-version; bh=J0nFsogWc5vJyIKsHnTYEKpnc+T7cuHmEOeDl6XINk8=; b=iqH+Gkvkj0kYZsUK27z9pIR+fnTZkf1u5UeDC3Shv7V9AZ9AHGCZtqjRBEy1WqPchZ 1Glqh10lQ4OvUN2NNBiCsDc0vvMZaajpsfS3FUDm9j5xB0efUQfALUSMxzDVqh6b5qKu qinVIOqiPLy39gYXSwS/FDLDcl8DZylNMJnoHzB3kzUm690wZAplM5nUmlv2u5nBN4pr EKIct/uVLoimlzT0bZuiBrQAO6p8oozA5ncpgUNEgpCv5ty4+cyHuif02zRZXB5RvCln hB9YbNfMA4BWrD1CRlXLUtUY/gYUB+D7PGnFUMePed2yChPczGrGkz2/9T4raQVNlseI 480g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version; bh=J0nFsogWc5vJyIKsHnTYEKpnc+T7cuHmEOeDl6XINk8=; b=zcAb7ZuNsDBbUGyeV6TQsVRiZVFCB0wLScilckfagvgkkhGvVvgWXcfPMhoF6zjBPi T25LGw1KJZYZfs4oYBqQlM/wsgWwzPgtOw8McVPQH6NcFTCSn2H9twBvfVzn9sVQcuxu /Aleu/hUmSsuCgnRPN2DD18vHnN+s0hHPl9QtM1F3W2OGFKRVY1PUq44JUZuHqIXPg19 9v/NwpJ6R5OxlE/NlAB6YcETi54Np7Pj60sDZmuF7jTp5oNWQCEVt3lTjv44CAxsPQdF f92AevgLvl6j6eLQfgwVNSlhC1+CzPFLm5aEbK+xpY7eSv6NdWubQDQ875erhQSrQZa9 olOg== X-Gm-Message-State: AOAM532wLbuZWJWfu0L96EJ+t6T0T2tHzp87ZB3hNSjlBSC3fe4214IU X5dRvd7wNyEBWNIl2e8V3wjWMw== X-Google-Smtp-Source: ABdhPJyr2bMvfzbC4iXBGXupqaBFeK5DEC/G+JtStA+e0bDWxUNbhHL/dA4Z+25ahlW83olTrlJpew== X-Received: by 2002:a05:620a:298a:: with SMTP id r10mr3764016qkp.295.1644703428940; Sat, 12 Feb 2022 14:03:48 -0800 (PST) Original-Received: from orion.rgrjr.com ([2601:19c:4600:3270::c]) by smtp.gmail.com with ESMTPSA id c21sm14927584qtx.89.2022.02.12.14.03.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Feb 2022 14:03:48 -0800 (PST) X-Host-Lookup-Failed: Reverse DNS lookup failed for 2607:f8b0:4864:20::731 (failed) Received-SPF: none client-ip=2607:f8b0:4864:20::731; envelope-from=rogers@rgrjr.com; helo=mail-qk1-x731.google.com X-Spam_score_int: -10 X-Spam_score: -1.1 X-Spam_bar: - X-Spam_report: (-1.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, PDS_HP_HELO_NORDNS=0.001, RCVD_IN_DNSWL_NONE=-0.0001, RDNS_NONE=0.793, SPF_HELO_NONE=0.001, SPF_NONE=0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=no autolearn_force=no X-Spam_action: no action 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:226752 Archived-At: In GNU Emacs 29.0.50 (build 1, x86_64-pc-linux-gnu, GTK+ Version 3.24.20, cairo version 1.16.0) of 2022-02-10 built on orion Repository revision: 2469e036035f8f5baa78e1557c61df019d8fd572 Repository branch: master Windowing system distributor 'The X.Org Foundation', version 11.0.12003000 System Description: openSUSE Leap 15.3 Configured using: 'configure --with-dbus=no --with-gsettings=no --with-gif=ifavailable --with-tiff=no --with-gnutls=yes --with-gconf=no' Configured features: ACL CAIRO FREETYPE GIF GLIB GMP GNUTLS HARFBUZZ JPEG LIBSELINUX LIBXML2 MODULES NOTIFY INOTIFY PDUMPER PNG RSVG SECCOMP SOUND SQLITE3 THREADS TOOLKIT_SCROLL_BARS X11 XDBE XIM XPM GTK3 ZLIB Evaluating (e.g.) (ietf-drums-remove-whitespace "random (unterminated comment") gets a scan-error, and similarly if the "(" is replaced with a "\"". The patch below makes it work, does some code consolidation, and adds regression tests. -- Bob Rogers http://www.rgrjr.com/ ------------------------------------------------------------------------ >From 97083141917360149b65851f4615fabc0d8c9462 Mon Sep 17 00:00:00 2001 From: Bob Rogers Date: Fri, 11 Feb 2022 23:42:17 -0500 Subject: [PATCH] Fix ietf-drums-remove-whitespace unmatched " and ( * lisp/mail/ietf-drums.el: + (ietf-drums-skip-comment): New helper function. + (ietf-drums-remove-comments): Use ietf-drums-skip-comment. + (ietf-drums-remove-whitespace): Handle unterminated quotes and comments, as ietf-drums-remove-comments already does. * test/lisp/mail/ietf-drums-tests.el: + Test unterminated quote and comment for ietf-drums-remove-whitespace and ietf-drums-remove-comments. --- lisp/mail/ietf-drums.el | 30 ++++++++++++++++++++---------- test/lisp/mail/ietf-drums-tests.el | 16 ++++++++++++++++ 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/lisp/mail/ietf-drums.el b/lisp/mail/ietf-drums.el index db77aba172..886de7c9d6 100644 --- a/lisp/mail/ietf-drums.el +++ b/lisp/mail/ietf-drums.el @@ -65,6 +65,21 @@ ietf-drums-syntax-table (modify-syntax-entry ?\' "_" table) table)) +(defvar ietf-drums-comment-syntax-table + (let ((table (copy-syntax-table ietf-drums-syntax-table))) + (modify-syntax-entry ?\" "w" table) + table) + "In comments, DQUOTE is normal and does not start a string.") + +(defun ietf-drums--skip-comment () + ;; From just before the start of a comment, go to the end. Returns + ;; point. If the comment is unterminated, go to point-max. + (condition-case () + (with-syntax-table ietf-drums-comment-syntax-table + (forward-sexp 1)) + (scan-error (goto-char (point-max)))) + (point)) + (defun ietf-drums-token-to-list (token) "Translate TOKEN into a list of characters." (let ((i 0) @@ -109,14 +124,7 @@ ietf-drums-remove-comments (forward-sexp 1) (error (goto-char (point-max))))) ((eq c ?\() - (delete-region - (point) - (condition-case nil - (with-syntax-table (copy-syntax-table ietf-drums-syntax-table) - (modify-syntax-entry ?\" "w") - (forward-sexp 1) - (point)) - (error (point-max))))) + (delete-region (point) (ietf-drums--skip-comment))) (t (forward-char 1)))) (buffer-string)))) @@ -130,9 +138,11 @@ ietf-drums-remove-whitespace (setq c (char-after)) (cond ((eq c ?\") - (forward-sexp 1)) + (condition-case () + (forward-sexp 1) + (scan-error (goto-char (point-max))))) ((eq c ?\() - (forward-sexp 1)) + (ietf-drums--skip-comment)) ((memq c '(?\ ?\t ?\n ?\r)) (delete-char 1)) (t diff --git a/test/lisp/mail/ietf-drums-tests.el b/test/lisp/mail/ietf-drums-tests.el index 4cc38b8763..b13937bf73 100644 --- a/test/lisp/mail/ietf-drums-tests.el +++ b/test/lisp/mail/ietf-drums-tests.el @@ -40,6 +40,16 @@ ietf-drums-tests (should (equal (ietf-drums-remove-comments "random (first) (second (and)) (third) not fourth") "random not fourth")) + ;; Test some unterminated comments. + (should (equal (ietf-drums-remove-comments "test an (unterminated comment") + "test an ")) + (should (equal (ietf-drums-remove-comments "test an \"unterminated quote") + ;; returns the string unchanged (and doesn't barf). + "test an \"unterminated quote")) + (should (equal (ietf-drums-remove-comments + ;; note that double-quote is not special. + "test (unterminated comments with \"quoted (\" )stuff") + "test ")) ;; ietf-drums-remove-whitespace (should (equal (ietf-drums-remove-whitespace "random string") @@ -53,6 +63,12 @@ ietf-drums-tests (should (equal (ietf-drums-remove-whitespace "random (first) (second (and)) (third) not fourth") "random(first)(second (and))(third)notfourth")) + ;; Test some unterminated comments and quotes. + (should (equal (ietf-drums-remove-whitespace + "random (first) (second (and)) (third unterminated") + "random(first)(second (and))(third unterminated")) + (should (equal (ietf-drums-remove-whitespace "random \"non terminated string") + "random\"non terminated string")) ;; ietf-drums-strip (should (equal (ietf-drums-strip "random string") "randomstring")) -- 2.34.1