From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 31821 invoked from network); 17 Apr 2022 19:44:52 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 17 Apr 2022 19:44:52 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1650224692; b=luMIuB8TE2pEhv3PH9oaoEj8IlO8SziL9KCdspcRBwG8I/+LR24hTqGcm1zHLczQSHfo6iNu8n dmJdNFEb1ALP77tFsLHUwSP120cK65cUhIggrJV6ifu93RxueuK8uuGmVAWGdJzC9ip0dqPTbv x2gI7ptP+e3lj6/3SpOtP+re+d1x/dh9xa+Xgbq0AcJ5lH5SG842fH1uTLPHaBGtMmeVAhQiT2 Qsat/AtTgP7y7NBfkSn02qSrzXYmT5NGqzsIpfQYASKj+BFUuzbMV4G64YaHzVfkpVASiIpe0Q 3NfjVvgxK6AnsDAbsiJnw5pmiJFwU1iAQqA367MdGcmPpg==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (wout4-smtp.messagingengine.com) smtp.remote-ip=64.147.123.20; dkim=pass header.d=daniel.shahaf.name header.s=fm3 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm1 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1650224692; bh=8ksFfw7SoF2M5u84yave4MtZgUJaWwkAhFYgnfUbNiQ=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Transfer-Encoding:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:DKIM-Signature: DKIM-Signature:DKIM-Signature; b=FsuBuq33NqlPsUG9GI9VEflGdQAXulwpYQdVO9O5Tw7vpUG/6550CGaP8ZSTexUdb36PmJ6oU+ RJnPkX6AWjT36uw8TClBCRgp4QJv8c5z7Q34hjvFsb1wI/YUkW7cX2I/tQM5NTcYqhNGXAg0qC lDMAb3IfAYoV4PblPv+iotKL7g1EyQTmrbMgqeX0hgvm4yjmz0wa31zQNlsB5GyWIMWU8V16rk Z4PvKl/6VusQ1owAUzvXVVTmEvgZvrLGGzRsKhxbN+8CXJB4Mr9WqZBLTfeT8IunhP0ttANPS9 O3l8Rfbsvtha042EEV5/lYfeMzxdEBR+cu3CnU5mC9sfEQ==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:In-Reply-To:Content-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID; bh=t0AZMii4y0WRLGHje9/0fT/w4ZHUSE+wzLGwQ7A5b/w=; b=IqZcBPy5Zfc0+DL3G4eO6gqV0o 3o53gNwNxcGtp8DzBRgW9Y2LtDmZoy2mIC/seoMWiKnTXQALQnf2ifxH8EkMUeUdMXfMqaYKAZt/H /s+YjYVfElAqX6QSE0AOqqOtI3o3qpQ9+KRe3oDG5+ehKBvlnma5eoyOT/QijulxoX08ud/nkEDbY pkjq8bs9A2cBoFvlrROIqh3CVbaYICxb53w97VDb3czzoe2cZCGCF6DblBrebemYJZvYw95YmEOTv 9UcIsVcQeYACth0LaPiMAeoE1hi/pJB484KgtSM0KUElxucg/343ozVQs1srGFRtoTlkqR/nCtT1Z XAG8Gphw==; Received: from authenticated user by zero.zsh.org with local id 1ngApH-000NV3-Bx; Sun, 17 Apr 2022 19:44:51 +0000 Authentication-Results: zsh.org; iprev=pass (wout4-smtp.messagingengine.com) smtp.remote-ip=64.147.123.20; dkim=pass header.d=daniel.shahaf.name header.s=fm3 header.a=rsa-sha256; dkim=pass header.d=messagingengine.com header.s=fm1 header.a=rsa-sha256; dmarc=none header.from=daniel.shahaf.name; arc=none Received: from wout4-smtp.messagingengine.com ([64.147.123.20]:41865) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1ngAoV-000MlR-Lv; Sun, 17 Apr 2022 19:44:05 +0000 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.west.internal (Postfix) with ESMTP id 4E7443200C17; Sun, 17 Apr 2022 15:44:01 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Sun, 17 Apr 2022 15:44:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= daniel.shahaf.name; h=cc:cc:content-transfer-encoding :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm3; t=1650224640; x=1650311040; bh=t0AZMii4y0 WRLGHje9/0fT/w4ZHUSE+wzLGwQ7A5b/w=; b=KSqOD3I6iYFCWIlZApVO41Uck2 lU1DWIiEjGxb2HYldfkslQ1H/vsd+X5EbQiZI+YIO0p8hSvS5iFiHMm6qlTMQiIZ kx2lc2gn58lZq+sEkRVa177VZcY758MQeUpsfhV3hQiCFw7hP+EHGgDeUVieqO17 RR6AQl+jVqyxQT8/7dflWbOCbMr3QwnikqfP9nc2pnkA0o/FvENZ2NaGNtpSGmv1 Y9yUySiuwyUEjseDikTB9gVUO+pLhzVG1+dSAFVdyumymudsFwfu48tNmxoHDgMk NFWNLhYgxxoHllGqrUh7xE5zK7XQIG3GNF0RVuM1bLgiXOZWn90EOFedcc6Q== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm1; t=1650224640; x=1650311040; bh=t0AZMii4y0WRL GHje9/0fT/w4ZHUSE+wzLGwQ7A5b/w=; b=jrYmdzGOhYX0gJqnkIrxhHq8fgBsH ZsB00EfCXjWeeX9J2f0t+6hub7ZW064cf6htjaPOI3gbwpEqlmInIcejMdgv7SFW rsEUTcaNqs7Z/adPxthA0wGK1z4IrqHbcORrCTynld/vhUTqK9/rDaMZM3gA0EwH V+SA1fSB6RNaJtOxQv68Aav/QcuR9Qe01DJhSw4rNHnH8hRbVK6ykywNsXhwczHg r8454OpTzC+hisT5fLDpggHKGoMyRYck8H82pws9+R8nN7Iu9fjob4MD0vFTzFS/ chAJiN8si2X+iNIM3XvhIIOJJFc408diMhOHgsqp0IlaBVPDY/FAIlO9g== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudelledgudegfecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtugfgjggfse htkedttddtreejnecuhfhrohhmpeffrghnihgvlhcuufhhrghhrghfuceougdrshesuggr nhhivghlrdhshhgrhhgrfhdrnhgrmhgvqeenucggtffrrghtthgvrhhnpefgkefgfeejgf dvvdfguddtleelkedvfeetiedtudfhveevveduhfdvveeffedvueenucevlhhushhtvghr ufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegurdhssegurghnihgvlhdrsh hhrghhrghfrdhnrghmvg X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Sun, 17 Apr 2022 15:44:00 -0400 (EDT) Received: by tarpaulin.shahaf.local2 (Postfix, from userid 1000) id 4KhL99541sz1th; Sun, 17 Apr 2022 19:43:57 +0000 (UTC) Date: Sun, 17 Apr 2022 19:43:57 +0000 From: Daniel Shahaf To: dg1727 Cc: zsh-users@zsh.org Subject: Re: Suggestion: Option to ignore unmatched quotes when (Q) parameter-expansion flag Message-ID: <20220417194357.GA15901@tarpaulin.shahaf.local2> References: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) X-Seq: 27665 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: List-Subscribe: List-Unsubscribe: List-Post: List-Owner: List-Archive: dg1727 wrote on Wed, Apr 13, 2022 at 21:12:13 +0000: > If variable ${u_input} contains the user's input, we start with > something equivalent to: ⋮ > a_string='one[abc]two' > if [[ "${a_string}" == ${u_input} ]] then > print "it matches" # Now it matches! > fi ⋮ > *** The current problem is the shell's handling of unbalanced > quotation marks: > > a_string='one[abc]"two' # unbalanced doublequote > > u_input='*[abc]"*' > # the user tries to match that doublequote and the [], all 3 literally > > u_input="${(Q)${(b)u_input}}" > > # u_input is now \*\[abc\]"\* > # the (Q) was skipped > > If we add the (X) flag to make (QX) so the shell will print an error > message, we find that the shell detects the unbalanced ("). > > The zshexpn documentation for X says "Without the [X] flag, errors are > silently ignored." It seems that, without (X), the unbalanced (") > isn't 'ignored,' but rather causes the (Q) flag to fail entirely. > > > *** I looked at the source code a little bit, and I have the following > suggestion, whose details are NOT terribly firm: ⋮ > Manpage zshexpn, section Parameter Expansion Flags: > change last sentence of description of X to: > Without the flag, errors silently cause the current processing step to be skipped. > > Add to the description of Q flag: > Handling of unbalanced quotes depends on whether the X flag is > present. > Also, if the Q flag is given twice and the X flag is *not* given, > then unbalanced quotation marks are silently ignored; other forms of > quoting are still removed. (For example, if a string contains an > unbalanced double-quote but the outermost level of quoting within > the string includes balanced single-quotes, then the single-quotes > will be removed.) A couple of points: - Wrap your lines to 80 columns. It's hard to read otherwise. - It's premature to go to this level of implementation details at this point in the discussion. More precisely, it can cause tunnel vision. We should consider all possible implementations of the proposed functinality, and all possible functionalities that may address the original use-case. - The best way to show proposed changes is by posting a unidiff (the output of `git diff`, attached in a file named *.txt). That's true even if the changes are alpha quality or even not meant to be applied at all. - I don't know that it makes sense to tie your program's glob syntax to zsh's input syntax (as opposed to zsh's pattern syntax, which is what plain «[[ $foo == $bar ]]» does). The fact that it's hard to implement is a clue in and of itself. You're essentially inventing your own string matching library here. - Now, if you actually wanted to use zsh's _input_ syntax, the obvious idea would be to use «eval» — but it's not trivial to implement that in a way that doesn't risk bobby tables bugs (e.g., if the pattern is «& pwd»). - Couldn't you simply append a «"» character to the user input and then use zsh unmodified? (You'd have to try three times: with no append, with an appended «"», with an appended «'».) Cheers, Daniel > Many thanks for your time. > > -dg1727 >