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=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 19539 invoked from network); 21 May 2020 07:07:08 -0000 Received: from ns1.primenet.com.au (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with ESMTPUTF8; 21 May 2020 07:07:08 -0000 Received: (qmail 1811 invoked by alias); 21 May 2020 07:06:27 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 45876 Received: (qmail 5349 invoked by uid 1010); 21 May 2020 07:06:27 -0000 X-Qmail-Scanner-Diagnostics: from out1-smtp.messagingengine.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.3/25814. spamassassin: 3.4.4. Clear:RC:0(66.111.4.25):SA:0(-2.6/5.0):. Processed in 6.146005 secs); 21 May 2020 07:06:27 -0000 X-Envelope-From: d.s@daniel.shahaf.name X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: none (ns1.primenet.com.au: domain at daniel.shahaf.name does not designate permitted sender hosts) X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduhedruddutddguddufecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfgjfhfogggtgfesth hqtddtredtjeenucfhrhhomhepffgrnhhivghlucfuhhgrhhgrfhcuoegurdhssegurghn ihgvlhdrshhhrghhrghfrdhnrghmvgeqnecuggftrfgrthhtvghrnhephfdtteefheevue dthedutdeifeegteettdejtdffheduieeijeelteetkeduteehnecukfhppeejledrudej jedrudefgedrfeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfh hrohhmpegurdhssegurghnihgvlhdrshhhrghhrghfrdhnrghmvg X-ME-Proxy: Date: Thu, 21 May 2020 07:05:39 +0000 From: Daniel Shahaf To: zsh-workers@zsh.org Subject: Re: [PATCH] vared: Escape empty elements of arrays Message-ID: <20200521070539.46a6e9de@tarpaulin.shahaf.local2> In-Reply-To: <20200519235425.13713-1-danielsh@tarpaulin.shahaf.local2> References: <20200519235425.13713-1-danielsh@tarpaulin.shahaf.local2> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Daniel Shahaf wrote on Tue, 19 May 2020 23:54 +0000: > +++ b/Test/X05zlebuiltins.ztst > @@ -0,0 +1,22 @@ > +%test > + > + zpty_run 'a=3D("foo foo" "" "bar")' > + zletest $'vared a\n\C-xw' > +0:vared: basic quoting test > +>BUFFER: foo\ foo '' bar > +>CURSOR: 15 =20 The patch is wrong, and the test here is incomplete. First, because of how vared works=C2=A0=E2=80=94 > > If an array or array slice is being edited, separator characters as def= ined > > in tt($IFS) will be shown quoted with a backslash, as will backslashes > > themselves. Conversely, when the edited text is split into an array, a > > backslash quotes an immediately following separator character or backsl= ash; > > no other special handling of backslashes, or any handling of quotes, is > > performed. =E2=80=94 it seems to be impossible for the result of a vared operation to include empty elements. In particular, editing an array with empty elements in master silently drops them. With the patch, the elements would become =C2=AB''=C2=BB (two bytes). The test didn't catch this because it didn't check the variable's value after the edit. --- I assume there should be a way to use vared to make an array element empty. Since the documentation specifically promises its own quoting semantics, I guess we have to continue to support them, even if we might've designed differently if we could redesign it from scratch. All in all, I guess we should add another a mode where vared would use normal shell quoting semantics. For array variables that'd be well-defined. For editing scalars there'd be a question of how to handle unescaped spaces. I'll fix the test and commit it later, but I don't have the brainwidth to add support for empty elements if it's not just a quick fix. Patches welcome. Cheers, Daniel