zsh-workers
 help / color / mirror / code / Atom feed
From: Daniel Shahaf <d.s@daniel.shahaf.name>
To: zsh-workers@zsh.org
Subject: Re: [PATCH] vared: Escape empty elements of arrays
Date: Thu, 21 May 2020 07:05:39 +0000	[thread overview]
Message-ID: <20200521070539.46a6e9de@tarpaulin.shahaf.local2> (raw)
In-Reply-To: <20200519235425.13713-1-danielsh@tarpaulin.shahaf.local2>

Daniel Shahaf wrote on Tue, 19 May 2020 23:54 +0000:
> +++ b/Test/X05zlebuiltins.ztst
> @@ -0,0 +1,22 @@
> +%test
> +
> +  zpty_run 'a=("foo foo" "" "bar")'
> +  zletest $'vared a\n\C-xw'
> +0:vared: basic quoting test
> +>BUFFER: foo\ foo '' bar
> +>CURSOR: 15  

The patch is wrong, and the test here is incomplete.

First, because of how vared works —

> > If an array or array slice is being edited, separator characters as defined
> > 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 backslash;
> > no other special handling of backslashes, or any handling of quotes, is
> > performed.

— 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 «''» (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

  reply	other threads:[~2020-05-21  7:07 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-19 23:54 Daniel Shahaf
2020-05-21  7:05 ` Daniel Shahaf [this message]
2020-05-21 10:57   ` Oliver Kiddle
2020-05-21 16:32     ` Daniel Shahaf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200521070539.46a6e9de@tarpaulin.shahaf.local2 \
    --to=d.s@daniel.shahaf.name \
    --cc=zsh-workers@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).